From 392984f2761cc6fd1123652bead2e106afdc83e5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 16 Aug 2016 19:53:10 +0300 Subject: [PATCH] New way of working with boxes (layers). Now the background of boxes is separated to another widget. This will allow to use a special layer widget (like settings) together with the usual layers-boxes upon it, moving the special widget behind the dark background when a usual layer-box is shown. --- Telegram/SourceFiles/app.h | 2 - Telegram/SourceFiles/boxes/aboutbox.cpp | 8 - Telegram/SourceFiles/boxes/aboutbox.h | 18 +- Telegram/SourceFiles/boxes/abstractbox.cpp | 54 +-- Telegram/SourceFiles/boxes/abstractbox.h | 38 +- Telegram/SourceFiles/boxes/addcontactbox.cpp | 81 +--- Telegram/SourceFiles/boxes/addcontactbox.h | 122 ++---- Telegram/SourceFiles/boxes/autolockbox.cpp | 13 - Telegram/SourceFiles/boxes/autolockbox.h | 10 +- Telegram/SourceFiles/boxes/backgroundbox.cpp | 5 +- Telegram/SourceFiles/boxes/backgroundbox.h | 25 +- Telegram/SourceFiles/boxes/confirmbox.cpp | 36 +- Telegram/SourceFiles/boxes/confirmbox.h | 81 ++-- Telegram/SourceFiles/boxes/confirmphonebox.h | 5 +- Telegram/SourceFiles/boxes/connectionbox.cpp | 32 +- Telegram/SourceFiles/boxes/connectionbox.h | 24 +- Telegram/SourceFiles/boxes/contactsbox.cpp | 19 +- Telegram/SourceFiles/boxes/contactsbox.h | 79 ++-- .../SourceFiles/boxes/downloadpathbox.cpp | 15 +- Telegram/SourceFiles/boxes/downloadpathbox.h | 11 +- Telegram/SourceFiles/boxes/emojibox.h | 9 +- Telegram/SourceFiles/boxes/languagebox.cpp | 15 +- Telegram/SourceFiles/boxes/languagebox.h | 12 +- Telegram/SourceFiles/boxes/passcodebox.cpp | 26 +- Telegram/SourceFiles/boxes/passcodebox.h | 20 +- Telegram/SourceFiles/boxes/photocropbox.cpp | 9 +- Telegram/SourceFiles/boxes/photocropbox.h | 19 +- Telegram/SourceFiles/boxes/photosendbox.cpp | 25 +- Telegram/SourceFiles/boxes/photosendbox.h | 40 +- Telegram/SourceFiles/boxes/report_box.cpp | 5 +- Telegram/SourceFiles/boxes/report_box.h | 5 +- Telegram/SourceFiles/boxes/sessionsbox.cpp | 11 - Telegram/SourceFiles/boxes/sessionsbox.h | 21 +- Telegram/SourceFiles/boxes/stickersetbox.cpp | 23 - Telegram/SourceFiles/boxes/stickersetbox.h | 22 +- Telegram/SourceFiles/boxes/usernamebox.cpp | 15 +- Telegram/SourceFiles/boxes/usernamebox.h | 15 +- Telegram/SourceFiles/facades.cpp | 2 +- Telegram/SourceFiles/facades.h | 4 +- Telegram/SourceFiles/historywidget.cpp | 6 +- Telegram/SourceFiles/historywidget.h | 15 +- Telegram/SourceFiles/layerwidget.cpp | 414 +++++++++++++----- Telegram/SourceFiles/layerwidget.h | 99 +++-- Telegram/SourceFiles/mainwidget.cpp | 28 +- Telegram/SourceFiles/mainwindow.cpp | 43 +- Telegram/SourceFiles/mainwindow.h | 16 +- .../SourceFiles/profile/profile_cover.cpp | 2 +- Telegram/SourceFiles/settings/settings.style | 23 + .../SourceFiles/settings/settings_widget.cpp | 26 ++ .../SourceFiles/settings/settings_widget.h | 25 ++ Telegram/SourceFiles/settingswidget.cpp | 14 +- Telegram/SourceFiles/ui/countryinput.cpp | 12 +- Telegram/SourceFiles/ui/countryinput.h | 58 +-- Telegram/gyp/Telegram.gyp | 3 + 54 files changed, 770 insertions(+), 990 deletions(-) create mode 100644 Telegram/SourceFiles/settings/settings.style create mode 100644 Telegram/SourceFiles/settings/settings_widget.cpp create mode 100644 Telegram/SourceFiles/settings/settings_widget.h diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 6dc19af13..cc34e5fda 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -42,8 +42,6 @@ typedef QHash GifItems; typedef QHash PhotosData; typedef QHash DocumentsData; -class LayeredWidget; - namespace App { AppClass *app(); MainWindow *wnd(); diff --git a/Telegram/SourceFiles/boxes/aboutbox.cpp b/Telegram/SourceFiles/boxes/aboutbox.cpp index 7e64bd52d..4b2e16d0d 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.cpp +++ b/Telegram/SourceFiles/boxes/aboutbox.cpp @@ -48,14 +48,6 @@ AboutBox::AboutBox() : AbstractBox(st::aboutWidth) setAcceptDrops(true); } -void AboutBox::hideAll() { - _version.hide(); - _text1.hide(); - _text2.hide(); - _text3.hide(); - _done.hide(); -} - void AboutBox::showAll() { _version.show(); _text1.show(); diff --git a/Telegram/SourceFiles/boxes/aboutbox.h b/Telegram/SourceFiles/boxes/aboutbox.h index 45af6b009..99d5571f5 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.h +++ b/Telegram/SourceFiles/boxes/aboutbox.h @@ -27,29 +27,25 @@ class AboutBox : public AbstractBox { Q_OBJECT public: - AboutBox(); - void resizeEvent(QResizeEvent *e); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - - void dragEnterEvent(QDragEnterEvent *e); - void dropEvent(QDropEvent *e); public slots: - void onVersion(); protected: + void resizeEvent(QResizeEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void dragEnterEvent(QDragEnterEvent *e) override; + void dropEvent(QDropEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - LinkButton _version; FlatLabel _text1, _text2, _text3; BoxButton _done; + }; QString telegramFaqLink(); diff --git a/Telegram/SourceFiles/boxes/abstractbox.cpp b/Telegram/SourceFiles/boxes/abstractbox.cpp index 16d58c864..0b80a12aa 100644 --- a/Telegram/SourceFiles/boxes/abstractbox.cpp +++ b/Telegram/SourceFiles/boxes/abstractbox.cpp @@ -73,28 +73,25 @@ void BlueTitleClose::paintEvent(QPaintEvent *e) { } } -AbstractBox::AbstractBox(int32 w) : LayeredWidget() +AbstractBox::AbstractBox(int32 w) : LayerWidget() , _maxHeight(0) -, _hiding(false) , _closed(false) -, a_opacity(0, 1) , _blueTitle(false) , _blueClose(0) , _blueShadow(0) { + setAttribute(Qt::WA_OpaquePaintEvent); resize(w, 0); } void AbstractBox::prepare() { showAll(); - _cache = myGrab(this); - hideAll(); } void AbstractBox::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { onClose(); } else { - LayeredWidget::keyPressEvent(e); + LayerWidget::keyPressEvent(e); } } @@ -115,17 +112,8 @@ void AbstractBox::parentResized() { } bool AbstractBox::paint(QPainter &p) { - bool result = true; - if (_cache.isNull()) { - result = (_hiding && a_opacity.current() < 0.01); - - // fill bg - p.fillRect(rect(), st::boxBg->b); - } else { - p.setOpacity(a_opacity.current()); - p.drawPixmap(0, 0, _cache); - } - return result; + p.fillRect(rect(), st::boxBg); + return false; } void AbstractBox::paintTitle(Painter &p, const QString &title, const QString &additional) { @@ -153,21 +141,6 @@ void AbstractBox::paintEvent(QPaintEvent *e) { if (paint(p)) return; } -void AbstractBox::showStep(float64 ms) { - if (ms >= 1) { - a_opacity.finish(); - _cache = QPixmap(); - setAttribute(Qt::WA_OpaquePaintEvent); - if (!_hiding) { - showAll(); - showDone(); - } - } else { - a_opacity.update(ms, anim::linear); - } - update(); -} - void AbstractBox::setMaxHeight(int32 maxHeight) { resizeMaxHeight(width(), maxHeight); } @@ -200,17 +173,7 @@ void AbstractBox::onClose() { _closed = true; closePressed(); } - emit closed(); -} - -void AbstractBox::startHide() { - _hiding = true; - if (_cache.isNull()) { - _cache = myGrab(this); - hideAll(); - } - a_opacity.start(0); - setAttribute(Qt::WA_OpaquePaintEvent, false); + emit closed(this); } void AbstractBox::setBlueTitle(bool blue) { @@ -248,11 +211,6 @@ void ScrollableBox::init(QWidget *inner, int32 bottomSkip, int32 topSkip) { ScrollableBox::resizeEvent(0); } -void ScrollableBox::hideAll() { - _scroll.hide(); - AbstractBox::hideAll(); -} - void ScrollableBox::showAll() { _scroll.show(); AbstractBox::showAll(); diff --git a/Telegram/SourceFiles/boxes/abstractbox.h b/Telegram/SourceFiles/boxes/abstractbox.h index 08d4a7d4d..560454bdf 100644 --- a/Telegram/SourceFiles/boxes/abstractbox.h +++ b/Telegram/SourceFiles/boxes/abstractbox.h @@ -47,27 +47,26 @@ private: }; -class AbstractBox : public LayeredWidget { +class AbstractBox : public LayerWidget { Q_OBJECT public: - AbstractBox(int32 w = st::boxWideWidth); - void parentResized(); - void showStep(float64 ms); - void keyPressEvent(QKeyEvent *e); - void resizeEvent(QResizeEvent *e); - void paintEvent(QPaintEvent *e); - void startHide(); + void parentResized() override; + void showDone() override { + showAll(); + } void setBlueTitle(bool blue); void raiseShadow(); public slots: - void onClose(); protected: + void keyPressEvent(QKeyEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; void prepare(); bool paint(QPainter &p); @@ -77,31 +76,21 @@ protected: virtual void closePressed() { } - virtual void hideAll() { - if (_blueClose) _blueClose->hide(); - if (_blueShadow) _blueShadow->hide(); - } virtual void showAll() { if (_blueClose) _blueClose->show(); if (_blueShadow) _blueShadow->show(); } - virtual void showDone() { - setFocus(); - } private: - int32 _maxHeight; int32 countHeight() const; - bool _hiding, _closed; - QPixmap _cache; - - anim::fvalue a_opacity; + bool _closed; bool _blueTitle; BlueTitleClose *_blueClose; BlueTitleShadow *_blueShadow; + }; class ScrollableBoxShadow : public PlainShadow { @@ -112,21 +101,17 @@ public: class ScrollableBox : public AbstractBox { public: - ScrollableBox(const style::flatScroll &scroll, int32 w = st::boxWideWidth); void resizeEvent(QResizeEvent *e); protected: - void init(QWidget *inner, int32 bottomSkip = st::boxScrollSkip, int32 topSkip = st::boxTitleHeight); - virtual void hideAll(); - virtual void showAll(); + void showAll() override; ScrollArea _scroll; private: - QWidget *_innerPtr; int32 _topSkip, _bottomSkip; @@ -134,7 +119,6 @@ private: class ItemListBox : public ScrollableBox { public: - ItemListBox(const style::flatScroll &scroll, int32 w = st::boxWideWidth); }; diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index e5274942d..897f6e3bb 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -84,15 +84,6 @@ void AddContactBox::initBox() { prepare(); } -void AddContactBox::hideAll() { - _first.hide(); - _last.hide(); - _phone.hide(); - _save.hide(); - _cancel.hide(); - _retry.hide(); -} - void AddContactBox::showAll() { _first.show(); _last.show(); @@ -101,7 +92,7 @@ void AddContactBox::showAll() { _cancel.show(); } -void AddContactBox::showDone() { +void AddContactBox::doSetInnerFocus() { if ((_first.getLastText().isEmpty() && _last.getLastText().isEmpty()) || !_phone.isEnabled()) { (_invertOrder ? _last : _first).setFocus(); } else { @@ -203,7 +194,7 @@ bool AddContactBox::onSaveUserFail(const RPCError &error) { QString firstName = _first.getLastText().trimmed(), lastName = _last.getLastText().trimmed(); if (err == "CHAT_TITLE_NOT_MODIFIED") { _user->setName(firstName, lastName, _user->nameOrPhone, _user->username); - emit closed(); + onClose(); return true; } else if (err == "NO_CHAT_TITLE") { _first.setFocus(); @@ -243,9 +234,9 @@ void AddContactBox::onImportDone(const MTPcontacts_ImportedContacts &res) { } void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) { - const auto &d(res.c_contacts_importedContacts()); + auto &d = res.c_contacts_importedContacts(); App::feedUsers(d.vusers); - emit closed(); + onClose(); } void AddContactBox::onRetry() { @@ -282,13 +273,6 @@ _cancel(this, lang(lng_cancel), st::cancelBoxButton) { prepare(); } -void NewGroupBox::hideAll() { - _group.hide(); - _channel.hide(); - _cancel.hide(); - _next.hide(); -} - void NewGroupBox::showAll() { _group.show(); _channel.show(); @@ -296,10 +280,6 @@ void NewGroupBox::showAll() { _next.show(); } -void NewGroupBox::showDone() { - setFocus(); -} - void NewGroupBox::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { onNext(); @@ -364,13 +344,6 @@ _creationRequestId(0), _createdChannel(0) { prepare(); } -void GroupInfoBox::hideAll() { - _title.hide(); - _description.hide(); - _cancel.hide(); - _next.hide(); -} - void GroupInfoBox::showAll() { _title.show(); if (_creating == CreatingGroupChannel) { @@ -382,7 +355,7 @@ void GroupInfoBox::showAll() { _next.show(); } -void GroupInfoBox::showDone() { +void GroupInfoBox::doSetInnerFocus() { _title.setFocus(); } @@ -637,14 +610,6 @@ SetupChannelBox::SetupChannelBox(ChannelData *channel, bool existing) : Abstract prepare(); } -void SetupChannelBox::hideAll() { - _public.hide(); - _private.hide(); - _link.hide(); - _save.hide(); - _skip.hide(); -} - void SetupChannelBox::showAll() { _public.show(); _private.show(); @@ -657,8 +622,12 @@ void SetupChannelBox::showAll() { _skip.show(); } -void SetupChannelBox::showDone() { - _link.setFocus(); +void SetupChannelBox::doSetInnerFocus() { + if (_link.isHidden()) { + setFocus(); + } else { + _link.setFocus(); + } } void SetupChannelBox::updateMaxHeight() { @@ -1007,13 +976,6 @@ _requestId(0) { prepare(); } -void EditNameTitleBox::hideAll() { - _first.hide(); - _last.hide(); - _save.hide(); - _cancel.hide(); -} - void EditNameTitleBox::showAll() { _first.show(); if (_peer->isChat()) { @@ -1025,7 +987,7 @@ void EditNameTitleBox::showAll() { _cancel.show(); } -void EditNameTitleBox::showDone() { +void EditNameTitleBox::doSetInnerFocus() { (_invertOrder ? _last : _first).setFocus(); } @@ -1105,7 +1067,7 @@ void EditNameTitleBox::onSave() { void EditNameTitleBox::onSaveSelfDone(const MTPUser &user) { App::feedUsers(MTP_vector(1, user)); - emit closed(); + onClose(); } bool EditNameTitleBox::onSaveSelfFail(const RPCError &error) { @@ -1115,7 +1077,7 @@ bool EditNameTitleBox::onSaveSelfFail(const RPCError &error) { QString first = textOneLine(_first.getLastText().trimmed()), last = textOneLine(_last.getLastText().trimmed()); if (err == "NAME_NOT_MODIFIED") { App::self()->setName(first, last, QString(), textOneLine(App::self()->username)); - emit closed(); + onClose(); return true; } else if (err == "FIRSTNAME_INVALID") { _first.setFocus(); @@ -1139,7 +1101,7 @@ bool EditNameTitleBox::onSaveChatFail(const RPCError &error) { if (auto chatData = _peer->asChat()) { chatData->setName(_sentName); } - emit closed(); + onClose(); return true; } else if (err == qstr("NO_CHAT_TITLE")) { _first.setFocus(); @@ -1152,7 +1114,7 @@ bool EditNameTitleBox::onSaveChatFail(const RPCError &error) { void EditNameTitleBox::onSaveChatDone(const MTPUpdates &updates) { App::main()->sentUpdatesReceived(updates); - emit closed(); + onClose(); } EditChannelBox::EditChannelBox(ChannelData *channel) : AbstractBox() @@ -1188,15 +1150,6 @@ EditChannelBox::EditChannelBox(ChannelData *channel) : AbstractBox() prepare(); } -void EditChannelBox::hideAll() { - _title.hide(); - _description.hide(); - _sign.hide(); - _save.hide(); - _cancel.hide(); - _publicLink.hide(); -} - void EditChannelBox::showAll() { _title.show(); _description.show(); @@ -1214,7 +1167,7 @@ void EditChannelBox::showAll() { } } -void EditChannelBox::showDone() { +void EditChannelBox::doSetInnerFocus() { _title.setFocus(); } diff --git a/Telegram/SourceFiles/boxes/addcontactbox.h b/Telegram/SourceFiles/boxes/addcontactbox.h index e12ccc3aa..9cfd50917 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.h +++ b/Telegram/SourceFiles/boxes/addcontactbox.h @@ -26,30 +26,22 @@ class AddContactBox : public AbstractBox, public RPCSender { Q_OBJECT public: - AddContactBox(QString fname = QString(), QString lname = QString(), QString phone = QString()); AddContactBox(UserData *user); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - _first.setFocus(); - } public slots: - void onSubmit(); void onSave(); void onRetry(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void onImportDone(const MTPcontacts_ImportedContacts &res); void onSaveUserDone(const MTPcontacts_ImportedContacts &res); @@ -76,24 +68,19 @@ class NewGroupBox : public AbstractBox { Q_OBJECT public: - NewGroupBox(); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onNext(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; private: - Radiobutton _group, _channel; int32 _aboutGroupWidth, _aboutGroupHeight; Text _aboutGroup, _aboutChannel; @@ -105,20 +92,9 @@ class GroupInfoBox : public AbstractBox, public RPCSender { Q_OBJECT public: - GroupInfoBox(CreatingGroupType creating, bool fromTypeChoose); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void leaveEvent(QEvent *e); - - void setInnerFocus() { - _title.setFocus(); - } public slots: - void onPhoto(); void onPhotoReady(const QImage &img); @@ -127,13 +103,16 @@ public slots: void onDescriptionResized(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void leaveEvent(QEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void step_photoOver(float64 ms, bool timer); QRect photoRect() const; @@ -160,33 +139,16 @@ private: void creationDone(const MTPUpdates &updates); bool creationFail(const RPCError &e); void exportDone(const MTPExportedChatInvite &result); + }; class SetupChannelBox : public AbstractBox, public RPCSender { Q_OBJECT public: - SetupChannelBox(ChannelData *channel, bool existing = false); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void leaveEvent(QEvent *e); - - void closePressed(); - - void setInnerFocus() { - if (_link.isHidden()) { - setFocus(); - } else { - _link.setFocus(); - } - } public slots: - void onSave(); void onChange(); void onCheck(); @@ -194,13 +156,18 @@ public slots: void onPrivacyChange(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void leaveEvent(QEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void closePressed() override; + void showAll() override; + void doSetInnerFocus() override; private: - void updateSelected(const QPoint &cursorGlobalPosition); void step_goodFade(float64 ms, bool timer); @@ -234,34 +201,27 @@ private: Animation _a_goodFade; QTimer _checkTimer; + }; class EditNameTitleBox : public AbstractBox, public RPCSender { Q_OBJECT public: - EditNameTitleBox(PeerData *peer); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - _first.setFocus(); - } public slots: - void onSave(); void onSubmit(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void onSaveSelfDone(const MTPUser &user); bool onSaveSelfFail(const RPCError &error); @@ -278,26 +238,16 @@ private: mtpRequestId _requestId; QString _sentName; + }; class EditChannelBox : public AbstractBox, public RPCSender { Q_OBJECT public: - EditChannelBox(ChannelData *channel); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - if (!_description.hasFocus()) { - _title.setFocus(); - } - } public slots: - void peerUpdated(PeerData *peer); void onSave(); @@ -305,13 +255,14 @@ public slots: void onPublicLink(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void updateMaxHeight(); void onSaveTitleDone(const MTPUpdates &updates); @@ -333,4 +284,5 @@ private: mtpRequestId _saveTitleRequestId, _saveDescriptionRequestId, _saveSignRequestId; QString _sentTitle, _sentDescription; + }; diff --git a/Telegram/SourceFiles/boxes/autolockbox.cpp b/Telegram/SourceFiles/boxes/autolockbox.cpp index a755697ca..acb20f47d 100644 --- a/Telegram/SourceFiles/boxes/autolockbox.cpp +++ b/Telegram/SourceFiles/boxes/autolockbox.cpp @@ -53,13 +53,6 @@ _close(this, lang(lng_box_ok), st::defaultBoxButton) { prepare(); } -void AutoLockBox::hideAll() { - _close.hide(); - for (int32 i = 0, l = _options.size(); i < l; ++i) { - _options[i]->hide(); - } -} - void AutoLockBox::showAll() { _close.show(); for (int32 i = 0, l = _options.size(); i < l; ++i) { @@ -87,9 +80,3 @@ void AutoLockBox::onChange() { App::wnd()->checkAutoLock(); onClose(); } - -AutoLockBox::~AutoLockBox() { - for (int32 i = 0, l = _options.size(); i < l; ++i) { - delete _options[i]; - } -} diff --git a/Telegram/SourceFiles/boxes/autolockbox.h b/Telegram/SourceFiles/boxes/autolockbox.h index db7035972..075576ad0 100644 --- a/Telegram/SourceFiles/boxes/autolockbox.h +++ b/Telegram/SourceFiles/boxes/autolockbox.h @@ -26,22 +26,18 @@ class AutoLockBox : public AbstractBox { Q_OBJECT public: - AutoLockBox(); - void paintEvent(QPaintEvent *e); - ~AutoLockBox(); public slots: - void onChange(); protected: + void paintEvent(QPaintEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - QVector _options; BoxButton _close; + }; diff --git a/Telegram/SourceFiles/boxes/backgroundbox.cpp b/Telegram/SourceFiles/boxes/backgroundbox.cpp index 8567937cb..a4b8ff28d 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.cpp +++ b/Telegram/SourceFiles/boxes/backgroundbox.cpp @@ -172,9 +172,6 @@ void BackgroundInner::mouseReleaseEvent(QMouseEvent *e) { } } -BackgroundInner::~BackgroundInner() { -} - void BackgroundInner::resizeEvent(QResizeEvent *e) { } @@ -201,5 +198,5 @@ void BackgroundBox::onBackgroundChosen(int index) { if (App::main()) App::main()->setChatBackground(paper); if (App::settings()) App::settings()->needBackgroundUpdate(!paper.id); } - emit closed(); + onClose(); } diff --git a/Telegram/SourceFiles/boxes/backgroundbox.h b/Telegram/SourceFiles/boxes/backgroundbox.h index 4d3b5bfef..2c6455a54 100644 --- a/Telegram/SourceFiles/boxes/backgroundbox.h +++ b/Telegram/SourceFiles/boxes/backgroundbox.h @@ -26,23 +26,19 @@ class BackgroundInner : public QWidget, public RPCSender { Q_OBJECT public: - BackgroundInner(); - void paintEvent(QPaintEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void resizeEvent(QResizeEvent *e); - - ~BackgroundInner(); - signals: - void backgroundChosen(int index); -private: +protected: + void paintEvent(QPaintEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; +private: void gotWallpapers(const MTPVector &result); void updateWallpapers(); @@ -55,16 +51,15 @@ class BackgroundBox : public ItemListBox { Q_OBJECT public: - BackgroundBox(); - void paintEvent(QPaintEvent *e); public slots: - void onBackgroundChosen(int index); -private: +protected: + void paintEvent(QPaintEvent *e) override; +private: BackgroundInner _inner; }; diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 39c978ed3..d6799c34b 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -86,7 +86,7 @@ void ConfirmBox::mousePressEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateHover(); ClickHandler::pressed(); - return LayeredWidget::mousePressEvent(e); + return LayerWidget::mousePressEvent(e); } void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) { @@ -130,11 +130,6 @@ void ConfirmBox::closePressed() { emit cancelled(); } -void ConfirmBox::hideAll() { - _confirm.hide(); - _cancel.hide(); -} - void ConfirmBox::showAll() { if (_informative) { _confirm.show(); @@ -246,10 +241,6 @@ void MaxInviteBox::step_good(float64 ms, bool timer) { if (timer) update(); } -void MaxInviteBox::hideAll() { - _close.hide(); -} - void MaxInviteBox::showAll() { _close.show(); } @@ -342,11 +333,6 @@ bool ConvertToSupergroupBox::convertFail(const RPCError &error) { return true; } -void ConvertToSupergroupBox::hideAll() { - _convert.hide(); - _cancel.hide(); -} - void ConvertToSupergroupBox::showAll() { _convert.show(); _cancel.show(); @@ -417,13 +403,6 @@ void PinMessageBox::showAll() { _cancel.show(); } -void PinMessageBox::hideAll() { - _text.hide(); - _notify.hide(); - _pin.hide(); - _cancel.hide(); -} - void PinMessageBox::pinDone(const MTPUpdates &updates) { if (App::main()) { App::main()->sentUpdatesReceived(updates); @@ -497,15 +476,6 @@ void RichDeleteMessageBox::showAll() { _cancel.show(); } -void RichDeleteMessageBox::hideAll() { - _text.hide(); - _banUser.hide(); - _reportSpam.hide(); - _deleteAll.hide(); - _delete.hide(); - _cancel.hide(); -} - KickMemberBox::KickMemberBox(PeerData *chat, UserData *member) : ConfirmBox(lng_profile_sure_kick(lt_user, member->firstName), lang(lng_box_remove)) , _chat(chat) @@ -600,7 +570,3 @@ void ConfirmInviteBox::paintEvent(QPaintEvent *e) { void ConfirmInviteBox::showAll() { showChildren(); } - -void ConfirmInviteBox::hideAll() { - hideChildren(); -} diff --git a/Telegram/SourceFiles/boxes/confirmbox.h b/Telegram/SourceFiles/boxes/confirmbox.h index 11dabfaef..1fc81ff04 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.h +++ b/Telegram/SourceFiles/boxes/confirmbox.h @@ -28,39 +28,35 @@ class ConfirmBox : public AbstractBox, public ClickHandlerHost { Q_OBJECT public: - ConfirmBox(const QString &text, const QString &doneText = QString(), const style::RoundButton &doneStyle = st::defaultBoxButton, const QString &cancelText = QString(), const style::RoundButton &cancelStyle = st::cancelBoxButton); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void leaveEvent(QEvent *e); + void updateLink(); // ClickHandlerHost interface - void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active); - void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed); + void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; + void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; public slots: - void onCancel(); signals: - void confirmed(); void cancelled(); void cancelPressed(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void leaveEvent(QEvent *e) override; - void closePressed(); - void hideAll(); - void showAll(); + void closePressed() override; + void showAll() override; private: - ConfirmBox(const QString &text, const QString &doneText, const style::RoundButton &doneStyle, bool informative); friend class InformBox; @@ -76,12 +72,14 @@ private: QPoint _lastMousePos; BoxButton _confirm, _cancel; + }; class InformBox : public ConfirmBox { public: InformBox(const QString &text, const QString &doneText = QString(), const style::RoundButton &doneStyle = st::defaultBoxButton) : ConfirmBox(text, doneText, doneStyle, true) { } + }; class SharePhoneConfirmBox : public ConfirmBox { @@ -105,15 +103,12 @@ class ConfirmLinkBox : public ConfirmBox { Q_OBJECT public: - ConfirmLinkBox(const QString &url); public slots: - void onOpenLink(); private: - QString _url; }; @@ -122,21 +117,18 @@ class MaxInviteBox : public AbstractBox { Q_OBJECT public: - MaxInviteBox(const QString &link); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void leaveEvent(QEvent *e); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void leaveEvent(QEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - void updateSelected(const QPoint &cursorGlobalPosition); void step_good(float64 ms, bool timer); @@ -153,29 +145,26 @@ private: QString _goodTextLink; anim::fvalue a_goodOpacity; Animation _a_good; + }; class ConvertToSupergroupBox : public AbstractBox, public RPCSender { Q_OBJECT public: - ConvertToSupergroupBox(ChatData *chat); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onConvert(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - void convertDone(const MTPUpdates &updates); bool convertFail(const RPCError &error); @@ -184,28 +173,24 @@ private: int32 _textWidth, _textHeight; BoxButton _convert, _cancel; + }; class PinMessageBox : public AbstractBox, public RPCSender { Q_OBJECT public: - PinMessageBox(ChannelData *channel, MsgId msgId); - void resizeEvent(QResizeEvent *e); - public slots: - void onPin(); protected: + void resizeEvent(QResizeEvent *e) override; - void showAll(); - void hideAll(); + void showAll() override; private: - void pinDone(const MTPUpdates &updates); bool pinFail(const RPCError &error); @@ -225,22 +210,17 @@ class RichDeleteMessageBox : public AbstractBox, public RPCSender { Q_OBJECT public: - RichDeleteMessageBox(ChannelData *channel, UserData *from, MsgId msgId); - void resizeEvent(QResizeEvent *e); - public slots: - void onDelete(); protected: + void resizeEvent(QResizeEvent *e) override; - void showAll(); - void hideAll(); + void showAll() override; private: - ChannelData *_channel; UserData *_from; MsgId _msgId; @@ -278,7 +258,6 @@ protected: void paintEvent(QPaintEvent *e) override; void showAll() override; - void hideAll() override; private: ChildWidget _title, _status; diff --git a/Telegram/SourceFiles/boxes/confirmphonebox.h b/Telegram/SourceFiles/boxes/confirmphonebox.h index a19b8a371..f759824e9 100644 --- a/Telegram/SourceFiles/boxes/confirmphonebox.h +++ b/Telegram/SourceFiles/boxes/confirmphonebox.h @@ -40,13 +40,10 @@ private slots: protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void hideAll() override { - hideChildren(); - } void showAll() override { showChildren(); } - void showDone() override { + void doSetInnerFocus() override { _code->setFocus(); } diff --git a/Telegram/SourceFiles/boxes/connectionbox.cpp b/Telegram/SourceFiles/boxes/connectionbox.cpp index a08c723a4..659b3ddbf 100644 --- a/Telegram/SourceFiles/boxes/connectionbox.cpp +++ b/Telegram/SourceFiles/boxes/connectionbox.cpp @@ -54,21 +54,6 @@ ConnectionBox::ConnectionBox() : AbstractBox(st::boxWidth) prepare(); } -void ConnectionBox::hideAll() { - _autoRadio.hide(); - _httpProxyRadio.hide(); - _tcpProxyRadio.hide(); - _tryIPv6.hide(); - - _hostInput.hide(); - _portInput.hide(); - _userInput.hide(); - _passwordInput.hide(); - - _save.hide(); - _cancel.hide(); -} - void ConnectionBox::showAll() { _autoRadio.show(); _httpProxyRadio.show(); @@ -96,7 +81,7 @@ void ConnectionBox::showAll() { resizeEvent(0); } -void ConnectionBox::showDone() { +void ConnectionBox::doSetInnerFocus() { if (!_hostInput.isHidden()) { _hostInput.setFocus(); } @@ -218,7 +203,7 @@ void ConnectionBox::onSave() { MTP::restart(); reinitImageLinkManager(); reinitWebLoadManager(); - emit closed(); + onClose(); } } @@ -242,19 +227,6 @@ AutoDownloadBox::AutoDownloadBox() : AbstractBox(st::boxWidth) prepare(); } -void AutoDownloadBox::hideAll() { - _photoPrivate.hide(); - _photoGroups.hide(); - _audioPrivate.hide(); - _audioGroups.hide(); - _gifPrivate.hide(); - _gifGroups.hide(); - _gifPlay.hide(); - - _save.hide(); - _cancel.hide(); -} - void AutoDownloadBox::showAll() { _photoPrivate.show(); _photoGroups.show(); diff --git a/Telegram/SourceFiles/boxes/connectionbox.h b/Telegram/SourceFiles/boxes/connectionbox.h index 34a2770be..98f69e5b1 100644 --- a/Telegram/SourceFiles/boxes/connectionbox.h +++ b/Telegram/SourceFiles/boxes/connectionbox.h @@ -26,25 +26,21 @@ class ConnectionBox : public AbstractBox { Q_OBJECT public: - ConnectionBox(); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onChange(); void onSubmit(); void onSave(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - InputField _hostInput; PortInput _portInput; InputField _userInput; @@ -53,28 +49,25 @@ private: Checkbox _tryIPv6; BoxButton _save, _cancel; + }; class AutoDownloadBox : public AbstractBox { Q_OBJECT public: - AutoDownloadBox(); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onSave(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - Checkbox _photoPrivate, _photoGroups; Checkbox _audioPrivate, _audioGroups; Checkbox _gifPrivate, _gifGroups, _gifPlay; @@ -82,4 +75,5 @@ private: int32 _sectionHeight; BoxButton _save, _cancel; + }; diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 80b7ff537..c3de23233 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -1439,16 +1439,6 @@ bool ContactsBox::peopleFailed(const RPCError &error, mtpRequestId req) { return true; } -void ContactsBox::hideAll() { - _filter.hide(); - _filterCancel.hide(); - _next.hide(); - _cancel.hide(); - _topShadow.hide(); - if (_bottomShadow) _bottomShadow->hide(); - ItemListBox::hideAll(); -} - void ContactsBox::showAll() { _filter.show(); if (_filter.getLastText().isEmpty()) { @@ -1474,7 +1464,7 @@ void ContactsBox::showAll() { ItemListBox::showAll(); } -void ContactsBox::showDone() { +void ContactsBox::doSetInnerFocus() { _filter.setFocus(); } @@ -1725,7 +1715,7 @@ bool ContactsBox::creationFail(const RPCError &error) { _saveRequestId = 0; if (error.type() == "NO_CHAT_TITLE") { - emit closed(); + onClose(); return true; } else if (error.type() == "USERS_TOO_FEW") { _filter.setFocus(); @@ -2317,8 +2307,3 @@ void MembersBox::onAdminAdded() { _addBox = 0; _loadTimer.start(ReloadChannelMembersTimeout); } - -void MembersBox::showDone() { - _inner.clearSel(); - setFocus(); -} diff --git a/Telegram/SourceFiles/boxes/contactsbox.h b/Telegram/SourceFiles/boxes/contactsbox.h index d40ce5924..59c41c09a 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.h +++ b/Telegram/SourceFiles/boxes/contactsbox.h @@ -40,11 +40,9 @@ class ContactsInner : public TWidget, public RPCSender { Q_OBJECT private: - struct ContactData; public: - ContactsInner(CreatingGroupType creating = CreatingGroupNone); ContactsInner(ChannelData *channel, MembersFilter membersFilter, const MembersAlreadyIn &already); ContactsInner(ChatData *chat, MembersFilter membersFilter); @@ -52,13 +50,6 @@ public: void init(); void initList(); - void paintEvent(QPaintEvent *e); - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void resizeEvent(QResizeEvent *e); - void paintDialog(Painter &p, PeerData *peer, ContactData *data, bool sel); void updateFilter(QString filter = QString()); @@ -97,7 +88,6 @@ public: ~ContactsInner(); signals: - void mustScrollTo(int ymin, int ymax); void selectAllQuery(); void searchByUsername(); @@ -106,7 +96,6 @@ signals: void addRequested(); public slots: - void onDialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRow); void updateSel(); @@ -119,8 +108,15 @@ public slots: void onAllAdminsChanged(); -private: +protected: + void paintEvent(QPaintEvent *e) override; + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; +private: void updateSelectedRow(); void addAdminDone(const MTPUpdates &result, mtpRequestId req); bool addAdminFail(const RPCError &error, mtpRequestId req); @@ -193,29 +189,17 @@ class ContactsBox : public ItemListBox, public RPCSender { Q_OBJECT public: - ContactsBox(); ContactsBox(const QString &name, const QImage &photo); // group creation ContactsBox(ChannelData *channel); // channel setup ContactsBox(ChannelData *channel, MembersFilter filter, const MembersAlreadyIn &already); ContactsBox(ChatData *chat, MembersFilter filter); ContactsBox(UserData *bot); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void closePressed(); - - void setInnerFocus() { - _filter.setFocus(); - } signals: - void adminAdded(); public slots: - void onFilterUpdate(); void onFilterCancel(); void onChosenChanged(); @@ -231,13 +215,15 @@ public slots: void onNeedSearchByUsername(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void closePressed() override; + void showAll() override; + void doSetInnerFocus() override; private: - void init(); ContactsInner _inner; @@ -280,26 +266,18 @@ private: void creationDone(const MTPUpdates &updates); bool creationFail(const RPCError &e); + }; class MembersInner : public TWidget, public RPCSender { Q_OBJECT private: - struct MemberData; public: - MembersInner(ChannelData *channel, MembersFilter filter); - void paintEvent(QPaintEvent *e); - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void paintDialog(Painter &p, PeerData *peer, MemberData *data, bool sel, bool kickSel, bool kickDown); void selectSkip(int32 dir); @@ -323,13 +301,11 @@ public: ~MembersInner(); signals: - void mustScrollTo(int ymin, int ymax); void addRequested(); void loaded(); public slots: - void load(); void updateSel(); @@ -338,8 +314,15 @@ public slots: void onKickConfirm(); void onKickBoxDestroyed(QObject *obj); -private: +protected: + void paintEvent(QPaintEvent *e) override; + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; +private: void updateSelectedRow(); MemberData *data(int32 index); @@ -409,32 +392,24 @@ class MembersBox : public ItemListBox { Q_OBJECT public: - MembersBox(ChannelData *channel, MembersFilter filter); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - setFocus(); - } public slots: - void onScroll(); void onAdd(); void onAdminAdded(); protected: - - void showDone(); + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; private: - MembersInner _inner; ContactsBox *_addBox; SingleTimer _loadTimer; + }; diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.cpp b/Telegram/SourceFiles/boxes/downloadpathbox.cpp index 3da42b769..9aa2ca3e8 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.cpp +++ b/Telegram/SourceFiles/boxes/downloadpathbox.cpp @@ -51,17 +51,6 @@ DownloadPathBox::DownloadPathBox() : AbstractBox() prepare(); } -void DownloadPathBox::hideAll() { - _default.hide(); - _temp.hide(); - _dir.hide(); - - _pathLink.hide(); - - _save.hide(); - _cancel.hide(); -} - void DownloadPathBox::showAll() { _default.show(); _temp.show(); @@ -79,7 +68,7 @@ void DownloadPathBox::showAll() { int32 h = st::boxTitleHeight + st::boxOptionListPadding.top() + _default.height() + st::boxOptionListPadding.top() + _temp.height() + st::boxOptionListPadding.top() + _dir.height(); if (_dir.checked()) h += st::downloadPathSkip + _pathLink.height(); h += st::boxOptionListPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom(); - + setMaxHeight(h); } @@ -143,7 +132,7 @@ void DownloadPathBox::onSave() { cSetDownloadPath(_default.checked() ? QString() : (_temp.checked() ? qsl("tmp") : _path)); cSetDownloadPathBookmark((_default.checked() || _temp.checked()) ? QByteArray() : _pathBookmark); Local::writeUserSettings(); - emit closed(); + onClose(); } void DownloadPathBox::setPathText(const QString &text) { diff --git a/Telegram/SourceFiles/boxes/downloadpathbox.h b/Telegram/SourceFiles/boxes/downloadpathbox.h index 8f6e923b8..55fc27a82 100644 --- a/Telegram/SourceFiles/boxes/downloadpathbox.h +++ b/Telegram/SourceFiles/boxes/downloadpathbox.h @@ -26,24 +26,20 @@ class DownloadPathBox : public AbstractBox { Q_OBJECT public: - DownloadPathBox(); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onChange(); void onEditPath(); void onSave(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - void setPathText(const QString &text); QString _path; @@ -52,4 +48,5 @@ private: Radiobutton _default, _temp, _dir; LinkButton _pathLink; BoxButton _save, _cancel; + }; diff --git a/Telegram/SourceFiles/boxes/emojibox.h b/Telegram/SourceFiles/boxes/emojibox.h index 8fb3baac7..a04b49378 100644 --- a/Telegram/SourceFiles/boxes/emojibox.h +++ b/Telegram/SourceFiles/boxes/emojibox.h @@ -26,13 +26,13 @@ class EmojiBox : public AbstractBox { Q_OBJECT public: - EmojiBox(); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); + +protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; private: - void fillBlocks(); int32 _esize; @@ -47,4 +47,5 @@ private: typedef QVector BlockRow; typedef QVector Blocks; Blocks _blocks; + }; diff --git a/Telegram/SourceFiles/boxes/languagebox.cpp b/Telegram/SourceFiles/boxes/languagebox.cpp index 8c7fe47ed..f79bdaed6 100644 --- a/Telegram/SourceFiles/boxes/languagebox.cpp +++ b/Telegram/SourceFiles/boxes/languagebox.cpp @@ -65,13 +65,6 @@ _close(this, lang(lng_box_ok), st::defaultBoxButton) { prepare(); } -void LanguageBox::hideAll() { - _close.hide(); - for (int32 i = 0, l = _langs.size(); i < l; ++i) { - _langs[i]->hide(); - } -} - void LanguageBox::showAll() { _close.show(); for (int32 i = 0, l = _langs.size(); i < l; ++i) { @@ -123,7 +116,7 @@ void LanguageBox::onChange() { cancel = result.value(lng_cancel, langOriginal(lng_cancel)); ConfirmBox *box = new ConfirmBox(text, save, st::defaultBoxButton, cancel); connect(box, SIGNAL(confirmed()), this, SLOT(onSave())); - connect(box, SIGNAL(closed()), this, SLOT(onRestore())); + connect(box, SIGNAL(cancelled()), this, SLOT(onRestore())); Ui::showLayer(box, KeepOtherLayers); } } @@ -148,9 +141,3 @@ void LanguageBox::onSave() { } } } - -LanguageBox::~LanguageBox() { - for (int32 i = 0, l = _langs.size(); i < l; ++i) { - delete _langs[i]; - } -} diff --git a/Telegram/SourceFiles/boxes/languagebox.h b/Telegram/SourceFiles/boxes/languagebox.h index 68b7c65ce..8b0332e39 100644 --- a/Telegram/SourceFiles/boxes/languagebox.h +++ b/Telegram/SourceFiles/boxes/languagebox.h @@ -26,25 +26,21 @@ class LanguageBox : public AbstractBox { Q_OBJECT public: - LanguageBox(); - void mousePressEvent(QMouseEvent *e); - void paintEvent(QPaintEvent *e); - ~LanguageBox(); public slots: - void onChange(); void onRestore(); void onSave(); protected: + void mousePressEvent(QMouseEvent *e) override; + void paintEvent(QPaintEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - QVector _langs; BoxButton _close; + }; diff --git a/Telegram/SourceFiles/boxes/passcodebox.cpp b/Telegram/SourceFiles/boxes/passcodebox.cpp index 8468e86ff..49ffdf9a1 100644 --- a/Telegram/SourceFiles/boxes/passcodebox.cpp +++ b/Telegram/SourceFiles/boxes/passcodebox.cpp @@ -116,18 +116,6 @@ void PasscodeBox::init() { connect(&_recover, SIGNAL(clicked()), this, SLOT(onRecoverByEmail())); } -void PasscodeBox::hideAll() { - _oldPasscode.hide(); - _newPasscode.hide(); - _reenterPasscode.hide(); - _passwordHint.hide(); - _recoverEmail.hide(); - _recover.hide(); - _saveButton.hide(); - _cancelButton.hide(); - AbstractBox::hideAll(); -} - void PasscodeBox::showAll() { bool has = _cloudPwd ? (!_curSalt.isEmpty()) : cHasPasscode(); if (_turningOff) { @@ -265,7 +253,7 @@ void PasscodeBox::resizeEvent(QResizeEvent *e) { AbstractBox::resizeEvent(e); } -void PasscodeBox::showDone() { +void PasscodeBox::doSetInnerFocus() { if (_skipEmailWarning && !_recoverEmail.isHidden()) { _recoverEmail.setFocus(); } else if (_oldPasscode.isHidden()) { @@ -273,7 +261,6 @@ void PasscodeBox::showDone() { } else { _oldPasscode.setFocus(); } - _skipEmailWarning = false; } void PasscodeBox::setPasswordDone(const MTPBool &result) { @@ -419,7 +406,7 @@ void PasscodeBox::onSave(bool force) { Local::setPasscode(pwd.toUtf8()); App::wnd()->checkAutoLock(); App::wnd()->getTitle()->showUpdateBtn(); - emit closed(); + onClose(); } } @@ -523,13 +510,6 @@ RecoverBox::RecoverBox(const QString &pattern) : AbstractBox(st::boxWidth) prepare(); } -void RecoverBox::hideAll() { - _recoverCode.hide(); - _saveButton.hide(); - _cancelButton.hide(); - AbstractBox::hideAll(); -} - void RecoverBox::showAll() { _recoverCode.show(); _saveButton.show(); @@ -564,7 +544,7 @@ void RecoverBox::resizeEvent(QResizeEvent *e) { AbstractBox::resizeEvent(e); } -void RecoverBox::showDone() { +void RecoverBox::doSetInnerFocus() { _recoverCode.setFocus(); } diff --git a/Telegram/SourceFiles/boxes/passcodebox.h b/Telegram/SourceFiles/boxes/passcodebox.h index eecdf664f..4e1c212df 100644 --- a/Telegram/SourceFiles/boxes/passcodebox.h +++ b/Telegram/SourceFiles/boxes/passcodebox.h @@ -47,9 +47,8 @@ signals: protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void hideAll() override; void showAll() override; - void showDone() override; + void doSetInnerFocus() override; private: void init(); @@ -68,7 +67,7 @@ private: mtpRequestId _setRequest; QByteArray _newSalt, _curSalt; - bool _hasRecovery, _skipEmailWarning; + bool _hasRecovery, _skipEmailWarning = false; int32 _aboutHeight; @@ -81,35 +80,31 @@ private: LinkButton _recover; QString _oldError, _newError, _emailError; + }; class RecoverBox : public AbstractBox, public RPCSender { Q_OBJECT public: - RecoverBox(const QString &pattern); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onSubmit(); void onCodeChanged(); signals: - void reloadPassword(); void recoveryExpired(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void codeSubmitDone(bool recover, const MTPauth_Authorization &result); bool codeSubmitFail(const RPCError &error); @@ -121,4 +116,5 @@ private: InputField _recoverCode; QString _error; + }; diff --git a/Telegram/SourceFiles/boxes/photocropbox.cpp b/Telegram/SourceFiles/boxes/photocropbox.cpp index 390adc7a3..47a7c2cc9 100644 --- a/Telegram/SourceFiles/boxes/photocropbox.cpp +++ b/Telegram/SourceFiles/boxes/photocropbox.cpp @@ -80,7 +80,7 @@ void PhotoCropBox::init(const QImage &img, PeerData *peer) { } void PhotoCropBox::mousePressEvent(QMouseEvent *e) { - if (e->button() != Qt::LeftButton) return LayeredWidget::mousePressEvent(e); + if (e->button() != Qt::LeftButton) return LayerWidget::mousePressEvent(e); _downState = mouseState(e->pos()); _fromposx = e->pos().x(); @@ -89,7 +89,7 @@ void PhotoCropBox::mousePressEvent(QMouseEvent *e) { _fromcropy = _cropy; _fromcropw = _cropw; - return LayeredWidget::mousePressEvent(e); + return LayerWidget::mousePressEvent(e); } int32 PhotoCropBox::mouseState(QPoint p) { @@ -301,11 +301,6 @@ void PhotoCropBox::onReady(const QImage &tosend) { App::app()->uploadProfilePhoto(tosend, _peerId); } -void PhotoCropBox::hideAll() { - _done.hide(); - _cancel.hide(); -} - void PhotoCropBox::showAll() { _done.show(); _cancel.show(); diff --git a/Telegram/SourceFiles/boxes/photocropbox.h b/Telegram/SourceFiles/boxes/photocropbox.h index e7c63fd02..2a424bf5e 100644 --- a/Telegram/SourceFiles/boxes/photocropbox.h +++ b/Telegram/SourceFiles/boxes/photocropbox.h @@ -26,34 +26,29 @@ class PhotoCropBox : public AbstractBox { Q_OBJECT public: - PhotoCropBox(const QImage &img, const PeerId &peer); PhotoCropBox(const QImage &img, PeerData *peer); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void mouseMoveEvent(QMouseEvent *e); int32 mouseState(QPoint p); public slots: - void onSend(); void onReady(const QImage &tosend); signals: - void ready(const QImage &tosend); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - void init(const QImage &img, PeerData *peer); QString _title; diff --git a/Telegram/SourceFiles/boxes/photosendbox.cpp b/Telegram/SourceFiles/boxes/photosendbox.cpp index 08ddb2175..a7e996568 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.cpp +++ b/Telegram/SourceFiles/boxes/photosendbox.cpp @@ -304,13 +304,6 @@ void PhotoSendBox::closePressed() { } } -void PhotoSendBox::hideAll() { - _send.hide(); - _cancel.hide(); - _caption.hide(); - _compressed.hide(); -} - void PhotoSendBox::showAll() { _send.show(); _cancel.show(); @@ -325,8 +318,12 @@ void PhotoSendBox::showAll() { } } -void PhotoSendBox::showDone() { - setInnerFocus(); +void PhotoSendBox::doSetInnerFocus() { + if (_caption.isHidden()) { + setFocus(); + } else { + _caption.setFocus(); + } } void PhotoSendBox::onSend(bool ctrlShiftEnter) { @@ -622,20 +619,14 @@ void EditCaptionBox::resizeEvent(QResizeEvent *e) { _field->moveToLeft(st::boxPhotoPadding.left(), _save.y() - st::boxButtonPadding.top() - st::normalFont->height - _field->height()); } -void EditCaptionBox::hideAll() { - _save.hide(); - _cancel.hide(); - _field->hide(); -} - void EditCaptionBox::showAll() { _save.show(); _cancel.show(); _field->show(); } -void EditCaptionBox::showDone() { - setInnerFocus(); +void EditCaptionBox::doSetInnerFocus() { + _field->setFocus(); } void EditCaptionBox::onSave(bool ctrlShiftEnter) { diff --git a/Telegram/SourceFiles/boxes/photosendbox.h b/Telegram/SourceFiles/boxes/photosendbox.h index cc5801b7a..4856131d3 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.h +++ b/Telegram/SourceFiles/boxes/photosendbox.h @@ -27,36 +27,24 @@ class PhotoSendBox : public AbstractBox { Q_OBJECT public: - PhotoSendBox(const FileLoadResultPtr &file); PhotoSendBox(const QString &phone, const QString &fname, const QString &lname, MsgId replyTo); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - if (_caption.isHidden()) { - setFocus(); - } else { - _caption.setFocus(); - } - } public slots: - void onCompressedChange(); void onCaptionResized(); void onSend(bool ctrlShiftEnter = false); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void closePressed(); - void hideAll(); - void showAll(); - void showDone(); + void closePressed() override; + void showAll() override; + void doSetInnerFocus() override; private: - void updateBoxSize(); FileLoadResultPtr _file; @@ -87,30 +75,22 @@ class EditCaptionBox : public AbstractBox, public RPCSender { Q_OBJECT public: - EditCaptionBox(HistoryItem *msg); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); bool captionFound() const; - void setInnerFocus() { - _field->setFocus(); - } - public slots: - void onCaptionResized(); void onSave(bool ctrlShiftEnter = false); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void updateBoxSize(); void saveDone(const MTPUpdates &updates); diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index 97c50f225..0076f548b 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -24,6 +24,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include "styles/style_profile.h" #include "boxes/confirmbox.h" +#include "mainwindow.h" ReportBox::ReportBox(ChannelData *channel) : AbstractBox(st::boxWidth) , _channel(channel) @@ -85,10 +86,10 @@ void ReportBox::onChange() { _reasonOtherText.destroy(); updateMaxHeight(); } - setInnerFocus(); + if (App::wnd()) App::wnd()->setInnerFocus(); } -void ReportBox::setInnerFocus() { +void ReportBox::doSetInnerFocus() { if (_reasonOtherText) { _reasonOtherText->setFocus(); } else { diff --git a/Telegram/SourceFiles/boxes/report_box.h b/Telegram/SourceFiles/boxes/report_box.h index d4d08eb16..39954c348 100644 --- a/Telegram/SourceFiles/boxes/report_box.h +++ b/Telegram/SourceFiles/boxes/report_box.h @@ -40,10 +40,7 @@ protected: void showAll() override { showChildren(); } - void hideAll() override { - hideChildren(); - } - void setInnerFocus() override; + void doSetInnerFocus() override; private: void updateMaxHeight(); diff --git a/Telegram/SourceFiles/boxes/sessionsbox.cpp b/Telegram/SourceFiles/boxes/sessionsbox.cpp index 06d84ced1..03ac71a7d 100644 --- a/Telegram/SourceFiles/boxes/sessionsbox.cpp +++ b/Telegram/SourceFiles/boxes/sessionsbox.cpp @@ -220,12 +220,6 @@ void SessionsInner::listUpdated() { update(); } -SessionsInner::~SessionsInner() { - for (int32 i = 0, l = _terminateButtons.size(); i < l; ++i) { - delete _terminateButtons[i]; - } -} - SessionsBox::SessionsBox() : ScrollableBox(st::sessionsScroll) , _loading(true) , _inner(&_list, &_current) @@ -255,11 +249,6 @@ void SessionsBox::resizeEvent(QResizeEvent *e) { _done.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _done.height()); } -void SessionsBox::hideAll() { - _done.hide(); - ScrollableBox::hideAll(); -} - void SessionsBox::showAll() { _done.show(); if (_loading) { diff --git a/Telegram/SourceFiles/boxes/sessionsbox.h b/Telegram/SourceFiles/boxes/sessionsbox.h index e7d60fba9..51f84d021 100644 --- a/Telegram/SourceFiles/boxes/sessionsbox.h +++ b/Telegram/SourceFiles/boxes/sessionsbox.h @@ -37,24 +37,20 @@ class SessionsInner : public TWidget, public RPCSender { Q_OBJECT public: - SessionsInner(SessionsList *list, SessionData *current); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - void listUpdated(); - ~SessionsInner(); +protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; signals: - void oneTerminated(); void allTerminated(); void terminateAll(); public slots: - void onTerminate(); void onTerminateSure(); void onTerminateAll(); @@ -62,7 +58,6 @@ public slots: void onNoTerminateBox(QObject *obj); private: - void terminateDone(uint64 hash, const MTPBool &result); bool terminateFail(uint64 hash, const RPCError &error); @@ -85,13 +80,9 @@ class SessionsBox : public ScrollableBox, public RPCSender { Q_OBJECT public: - SessionsBox(); - void resizeEvent(QResizeEvent *e); - void paintEvent(QPaintEvent *e); public slots: - void onOneTerminated(); void onAllTerminated(); void onTerminateAll(); @@ -99,12 +90,12 @@ public slots: void onNewAuthorization(); protected: + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; - void hideAll(); - void showAll(); + void showAll() override; private: - void gotAuthorizations(const MTPaccount_Authorizations &result); bool _loading; diff --git a/Telegram/SourceFiles/boxes/stickersetbox.cpp b/Telegram/SourceFiles/boxes/stickersetbox.cpp index 5176838ac..a5edcba52 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.cpp +++ b/Telegram/SourceFiles/boxes/stickersetbox.cpp @@ -398,15 +398,6 @@ void StickerSetBox::onScroll() { _inner.setScrollBottom(_scroll.scrollTop() + _scroll.height()); } -void StickerSetBox::hideAll() { - ScrollableBox::hideAll(); - _shadow.hide(); - _cancel.hide(); - _add.hide(); - _share.hide(); - _done.hide(); -} - void StickerSetBox::showAll() { ScrollableBox::showAll(); int32 cnt = _inner.notInstalled(); @@ -1676,20 +1667,6 @@ void StickersBox::onSave() { } } -void StickersBox::hideAll() { - if (_topShadow) { - _topShadow->hide(); - } - if (_save) { - _save->hide(); - } - if (_cancel) { - _cancel->hide(); - _bottomShadow->hide(); - } - ItemListBox::hideAll(); -} - void StickersBox::showAll() { if (_topShadow) { _topShadow->show(); diff --git a/Telegram/SourceFiles/boxes/stickersetbox.h b/Telegram/SourceFiles/boxes/stickersetbox.h index cde1293f1..ef73191b2 100644 --- a/Telegram/SourceFiles/boxes/stickersetbox.h +++ b/Telegram/SourceFiles/boxes/stickersetbox.h @@ -90,12 +90,8 @@ class StickerSetBox : public ScrollableBox, public RPCSender { Q_OBJECT public: - StickerSetBox(const MTPInputStickerSet &set); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - public slots: void onStickersUpdated(); void onAddStickers(); @@ -111,8 +107,10 @@ signals: void installed(uint64 id); protected: - void hideAll(); - void showAll(); + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + + void showAll() override; private: StickerSetInner _inner; @@ -139,11 +137,6 @@ public: StickersBox(Section section = Section::Installed); StickersBox(const Stickers::Order &archivedIds); - void resizeEvent(QResizeEvent *e); - void paintEvent(QPaintEvent *e); - - void closePressed(); - ~StickersBox(); public slots: @@ -159,8 +152,11 @@ private slots: void onScroll(); protected: - void hideAll(); - void showAll(); + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; + + void closePressed() override; + void showAll() override; private: void setup(); diff --git a/Telegram/SourceFiles/boxes/usernamebox.cpp b/Telegram/SourceFiles/boxes/usernamebox.cpp index 3070baf2e..c4ae6190c 100644 --- a/Telegram/SourceFiles/boxes/usernamebox.cpp +++ b/Telegram/SourceFiles/boxes/usernamebox.cpp @@ -55,15 +55,6 @@ _about(st::boxWidth - st::usernamePadding.left()) { prepare(); } -void UsernameBox::hideAll() { - _username.hide(); - _save.hide(); - _cancel.hide(); - _link.hide(); - - AbstractBox::hideAll(); -} - void UsernameBox::showAll() { _username.show(); _save.show(); @@ -73,7 +64,7 @@ void UsernameBox::showAll() { AbstractBox::showAll(); } -void UsernameBox::showDone() { +void UsernameBox::doSetInnerFocus() { _username.setFocus(); } @@ -195,7 +186,7 @@ void UsernameBox::onLinkClick() { void UsernameBox::onUpdateDone(const MTPUser &user) { App::feedUsers(MTP_vector(1, user)); - emit closed(); + onClose(); } bool UsernameBox::onUpdateFail(const RPCError &error) { @@ -205,7 +196,7 @@ bool UsernameBox::onUpdateFail(const RPCError &error) { QString err(error.type()); if (err == qstr("USERNAME_NOT_MODIFIED") || _sentUsername == App::self()->username) { App::self()->setName(textOneLine(App::self()->firstName), textOneLine(App::self()->lastName), textOneLine(App::self()->nameOrPhone), textOneLine(_sentUsername)); - emit closed(); + onClose(); return true; } else if (err == qstr("USERNAME_INVALID")) { _username.setFocus(); diff --git a/Telegram/SourceFiles/boxes/usernamebox.h b/Telegram/SourceFiles/boxes/usernamebox.h index d2dfe0b6e..1af61399d 100644 --- a/Telegram/SourceFiles/boxes/usernamebox.h +++ b/Telegram/SourceFiles/boxes/usernamebox.h @@ -26,28 +26,24 @@ class UsernameBox : public AbstractBox, public RPCSender { Q_OBJECT public: - UsernameBox(); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); public slots: - void onSave(); - + void onCheck(); void onChanged(); void onLinkClick(); protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void hideAll(); - void showAll(); - void showDone(); + void showAll() override; + void doSetInnerFocus() override; private: - void onUpdateDone(const MTPUser &result); bool onUpdateFail(const RPCError &error); @@ -66,4 +62,5 @@ private: Text _about; QTimer _checkTimer; + }; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 936ea552d..6275b859f 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -194,7 +194,7 @@ void hideMediaPreview() { } } -void showLayer(LayeredWidget *box, ShowLayerOptions options) { +void showLayer(LayerWidget *box, ShowLayerOptions options) { if (auto w = App::wnd()) { w->ui_showLayer(box, options); } else { diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 364dc28da..5cb845f8f 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -20,7 +20,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -class LayeredWidget; +class LayerWidget; namespace App { @@ -56,7 +56,7 @@ void showMediaPreview(DocumentData *document); void showMediaPreview(PhotoData *photo); void hideMediaPreview(); -void showLayer(LayeredWidget *box, ShowLayerOptions options = CloseOtherLayers); +void showLayer(LayerWidget *box, ShowLayerOptions options = CloseOtherLayers); void hideLayer(bool fast = false); bool isLayerShown(); bool isMediaViewShown(); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index a5624d757..7d29a6295 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2760,7 +2760,7 @@ void HistoryHider::paintEvent(QPaintEvent *e) { toText.drawElided(p, box.left() + st::boxPadding.left(), box.top() + st::boxPadding.top(), toTextWidth + 2); } else { int32 w = st::forwardMargins.left() + _chooseWidth + st::forwardMargins.right(), h = st::forwardMargins.top() + st::forwardFont->height + st::forwardMargins.bottom(); - App::roundRect(p, (width() - w) / 2, (height() - h) / 2, w, h, st::forwardBg, ForwardCorners); + App::roundRect(p, (width() - w) / 2, (height() - st::titleHeight - h) / 2, w, h, st::forwardBg, ForwardCorners); p.setPen(st::white->p); p.drawText(box, lang(_botAndQuery.isEmpty() ? lng_forward_choose : lng_inline_switch_choose), QTextOption(style::al_center)); @@ -2849,7 +2849,7 @@ void HistoryHider::resizeEvent(QResizeEvent *e) { _send.hide(); _cancel.hide(); } - box = QRect((width() - w) / 2, (height() - h) / 2, w, h); + box = QRect((width() - w) / 2, (height() - st::titleHeight - 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()); } @@ -7742,7 +7742,7 @@ void HistoryWidget::onReplyToMessage() { onReplyToMessage(); App::contextItem(to); } else { - LayeredWidget *box = 0; + LayerWidget *box = nullptr; if (to->type() != HistoryItemMsg || to->serviceMsg()) { box = new InformBox(lang(lng_reply_cant)); } else { diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index ee97d4115..684d6c81c 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -433,7 +433,6 @@ class HistoryHider : public TWidget { Q_OBJECT public: - HistoryHider(MainWidget *parent, bool forwardSelected); // forward messages HistoryHider(MainWidget *parent, UserData *sharedContact); // share contact HistoryHider(MainWidget *parent); // send path from command line argument @@ -443,11 +442,6 @@ public: void step_appearance(float64 ms, bool timer); bool withConfirm() const; - void paintEvent(QPaintEvent *e); - void keyPressEvent(QKeyEvent *e); - void mousePressEvent(QMouseEvent *e); - void resizeEvent(QResizeEvent *e); - bool offerPeer(PeerId peer); QString offeredText() const; QString botAndQuery() const { @@ -460,17 +454,20 @@ public: ~HistoryHider(); -public slots: +protected: + void paintEvent(QPaintEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; +public slots: void startHide(); void forward(); signals: - void forwarded(); private: - void init(); MainWidget *parent(); diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index 602921043..c2fe4f63c 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -28,167 +28,357 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "ui/filedialog.h" -BackgroundWidget::BackgroundWidget(QWidget *parent, LayeredWidget *w) : TWidget(parent) -, w(w) -, a_bg(0) -, _a_background(animation(this, &BackgroundWidget::step_background)) -, hiding(false) -, shadow(st::boxShadow) { - w->setParent(this); - if (App::app()) App::app()->mtpPause(); - setGeometry(0, 0, App::wnd()->width(), App::wnd()->height()); - a_bg.start(1); - _a_background.start(); - show(); - connect(w, SIGNAL(closed()), this, SLOT(onInnerClose())); - connect(w, SIGNAL(resized()), this, SLOT(update())); - connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*))); - w->setFocus(); -} - -void BackgroundWidget::showFast() { - _a_background.step(getms() + st::layerSlideDuration + 1); - update(); -} - -void BackgroundWidget::paintEvent(QPaintEvent *e) { - if (!w) return; - bool trivial = (rect() == e->rect()); - - QPainter p(this); - if (!trivial) { - p.setClipRect(e->rect()); +void LayerWidget::setInnerFocus() { + auto focused = App::wnd()->focusWidget(); + if (!isAncestorOf(focused)) { + doSetInnerFocus(); } - p.setOpacity(st::layerAlpha * a_bg.current()); - p.fillRect(rect(), st::layerBg->b); - - p.setOpacity(a_bg.current()); - shadow.paint(p, w->geometry(), st::boxShadowShift); } -void BackgroundWidget::keyPressEvent(QKeyEvent *e) { +class LayerStackWidget::BackgroundWidget : public TWidget { +public: + BackgroundWidget(QWidget *parent) : TWidget(parent) + , _shadow(st::boxShadow) { + } + + void setLayerBox(const QRect &box) { + _box = box; + update(); + } + void setOpacity(float64 opacity) { + _opacity = opacity; + } + +protected: + void paintEvent(QPaintEvent *e) override { + Painter p(this); + + p.setOpacity(st::layerAlpha * _opacity); + if (_box.isNull()) { + p.fillRect(rect(), st::layerBg); + } else { + auto clip = QRegion(rect()) - _box; + for (auto &r : clip.rects()) { + p.fillRect(r, st::layerBg); + } + p.setClipRegion(clip); + p.setOpacity(_opacity); + _shadow.paint(p, _box, st::boxShadowShift); + } + } + +private: + QRect _box; + float64 _opacity = 0.; + + BoxShadow _shadow; + +}; + +LayerStackWidget::LayerStackWidget(QWidget *parent) : TWidget(parent) +, _background(this) +, a_bg(0) +, a_layer(0) +, _a_background(animation(this, &LayerStackWidget::step_background)) { + setGeometry(parentWidget()->rect()); + hide(); +} + +void LayerStackWidget::paintEvent(QPaintEvent *e) { + if (!layer() && !_specialLayer && _layerCache.isNull()) { + return; + } + + if (!_layerCache.isNull()) { + Painter p(this); + p.setClipRect(rect()); + p.setOpacity(a_layer.current()); + p.drawPixmap(_layerCacheBox.topLeft(), _layerCache); + } +} + +void LayerStackWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { onClose(); } } -void BackgroundWidget::mousePressEvent(QMouseEvent *e) { +void LayerStackWidget::mousePressEvent(QMouseEvent *e) { onClose(); } -void BackgroundWidget::onClose() { +void LayerStackWidget::onClose() { startHide(); } -bool BackgroundWidget::onInnerClose() { - if (_hidden.isEmpty()) { +void LayerStackWidget::onLayerClosed(LayerWidget *l) { + l->deleteLater(); + if (l == _specialLayer) { onClose(); + _specialLayer = nullptr; + } else if (l == layer()) { + _layers.pop_back(); + if (auto newLayer = layer()) { + l->hide(); + newLayer->parentResized(); + if (!_a_background.animating()) { + newLayer->show(); + } + } else if (_specialLayer) { + l->hide(); + } else { + _layers.push_back(l); // For animation cache grab. + onClose(); + _layers.pop_back(); + } + fixOrder(); + if (App::wnd()) App::wnd()->setInnerFocus(); + updateLayerBox(); + } else { + for (auto i = _layers.begin(), e = _layers.end(); i != e; ++i) { + if (l == *i) { + _layers.erase(i); + break; + } + } + } +} + +void LayerStackWidget::onLayerResized() { + updateLayerBox(); +} + +void LayerStackWidget::updateLayerBox() { + auto getLayerBox = [this]() { + if (!_layerCache.isNull()) { + return _layerCacheBox; + } else if (auto l = layer()) { + return l->geometry(); + } else if (_specialLayer) { + return _specialLayer->geometry(); + } + return QRect(); + }; + _background->setLayerBox(getLayerBox()); + update(); +} + +void LayerStackWidget::startShow() { + startAnimation(1); + show(); +} + +void LayerStackWidget::showFast() { + if (_a_background.animating()) { + _a_background.step(getms() + st::layerSlideDuration + 1); + } +} + +void LayerStackWidget::startHide() { + if (isHidden() || _hiding) { + return; + } + + _hiding = true; + startAnimation(0); +} + +void LayerStackWidget::startAnimation(float64 toOpacity) { + if (App::app()) App::app()->mtpPause(); + a_bg.start(toOpacity); + a_layer.start(toOpacity); + _a_background.start(); + if (_layerCache.isNull()) { + if (auto cacheLayer = layer() ? layer() : _specialLayer) { + _layerCache = myGrab(cacheLayer); + _layerCacheBox = cacheLayer->geometry(); + } + } + if (_specialLayer) { + _specialLayer->hide(); + } + if (auto l = layer()) { + l->hide(); + } + updateLayerBox(); + if (App::wnd()) App::wnd()->setInnerFocus(); +} + +bool LayerStackWidget::canSetFocus() const { + return (layer() || _specialLayer) && !_hiding; +} + +void LayerStackWidget::setInnerFocus() { + if (_a_background.animating()) { + setFocus(); + } else if (auto l = layer()) { + l->setInnerFocus(); + } else if (_specialLayer) { + _specialLayer->setInnerFocus(); + } +} + +bool LayerStackWidget::contentOverlapped(const QRect &globalRect) { + if (isHidden()) { + return false; + } + if (_specialLayer && _specialLayer->overlaps(globalRect)) { return true; } - w->hide(); - w->deleteLater(); - w = _hidden.back(); - _hidden.pop_back(); - w->show(); - resizeEvent(0); - w->showStep(1); - update(); + if (auto l = layer()) { + return l->overlaps(globalRect); + } return false; } -void BackgroundWidget::startHide() { - if (hiding) return; - if (App::app()) App::app()->mtpPause(); - - hiding = true; - if (App::wnd()) App::wnd()->setInnerFocus(); - a_bg.start(0); - _a_background.start(); - w->startHide(); +void LayerStackWidget::resizeEvent(QResizeEvent *e) { + _background->setGeometry(rect()); + if (_specialLayer) { + _specialLayer->parentResized(); + } + if (auto l = layer()) { + l->parentResized(); + } + updateLayerBox(); } -bool BackgroundWidget::canSetFocus() const { - return w && !hiding; +void LayerStackWidget::updateAdaptiveLayout() { } -void BackgroundWidget::setInnerFocus() { - if (w) { - w->setInnerFocus(); +void LayerStackWidget::showLayer(LayerWidget *l) { + clearLayers(); + appendLayer(l); +} + +void LayerStackWidget::showSpecialLayer(LayerWidget *l) { + clearLayers(); + if (_specialLayer) { + _specialLayer->hide(); + _specialLayer->deleteLater(); + } + _specialLayer = l; + activateLayer(l); +} + +void LayerStackWidget::appendLayer(LayerWidget *l) { + if (auto oldLayer = layer()) { + oldLayer->hide(); + } + _layers.push_back(l); + activateLayer(l); +} + +void LayerStackWidget::prependLayer(LayerWidget *l) { + if (_layers.empty()) { + showLayer(l); + } else { + l->hide(); + _layers.push_front(l); + initChildLayer(l); } } -bool BackgroundWidget::contentOverlapped(const QRect &globalRect) { - if (isHidden()) return false; - return w && w->overlaps(globalRect); +void LayerStackWidget::clearLayers() { + for_const (auto oldLayer, _layers) { + oldLayer->hide(); + oldLayer->deleteLater(); + } + _layers.clear(); } -void BackgroundWidget::resizeEvent(QResizeEvent *e) { - w->parentResized(); +void LayerStackWidget::initChildLayer(LayerWidget *l) { + l->setParent(this); + connect(l, SIGNAL(closed(LayerWidget*)), this, SLOT(onLayerClosed(LayerWidget*))); + connect(l, SIGNAL(resized()), this, SLOT(onLayerResized())); + connect(l, SIGNAL(destroyed(QObject*)), this, SLOT(onLayerDestroyed(QObject*))); + l->parentResized(); + fixOrder(); } -void BackgroundWidget::updateAdaptiveLayout() { +void LayerStackWidget::activateLayer(LayerWidget *l) { + initChildLayer(l); + if (isHidden()) { + startShow(); + } else { + l->show(); + if (App::wnd()) App::wnd()->setInnerFocus(); + updateLayerBox(); + } + fixOrder(); } -void BackgroundWidget::replaceInner(LayeredWidget *n) { - _hidden.push_back(w); - w->hide(); - w = n; - w->setParent(this); - connect(w, SIGNAL(closed()), this, SLOT(onInnerClose())); - connect(w, SIGNAL(resized()), this, SLOT(update())); - connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*))); - w->show(); - resizeEvent(0); - w->showStep(1); - update(); +void LayerStackWidget::fixOrder() { + if (auto l = layer()) { + _background->raise(); + l->raise(); + } else if (_specialLayer) { + _specialLayer->raise(); + } } -void BackgroundWidget::showLayerLast(LayeredWidget *n) { - _hidden.push_front(n); - n->setParent(this); - connect(n, SIGNAL(closed()), this, SLOT(onInnerClose())); - connect(n, SIGNAL(resized()), this, SLOT(update())); - connect(n, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*))); - n->parentResized(); - n->showStep(1); - n->hide(); - update(); -} - -void BackgroundWidget::step_background(float64 ms, bool timer) { - float64 dt = ms / (hiding ? st::layerHideDuration : st::layerSlideDuration); - w->showStep(dt); +void LayerStackWidget::step_background(float64 ms, bool timer) { + float64 dt = ms / (_hiding ? st::layerHideDuration : st::layerSlideDuration); if (dt >= 1) { a_bg.finish(); - if (hiding) { - App::wnd()->layerFinishedHide(this); - } + a_layer.finish(); _a_background.stop(); + _layerCache = QPixmap(); + if (_hiding) { + App::wnd()->layerFinishedHide(this); + } else { + if (_specialLayer) { + _specialLayer->show(); + _specialLayer->showDone(); + } + if (auto l = layer()) { + l->show(); + l->showDone(); + } + fixOrder(); + if (App::wnd()) App::wnd()->setInnerFocus(); + } + updateLayerBox(); if (App::app()) App::app()->mtpUnpause(); } else { a_bg.update(dt, anim::easeOutCirc); + a_layer.update(dt, anim::linear); + } + _background->setOpacity(a_bg.current()); + if (timer) { + _background->update(); + update(); } - if (timer) update(); } -void BackgroundWidget::boxDestroyed(QObject *obj) { - if (obj == w) { - if (App::wnd()) App::wnd()->layerFinishedHide(this); - w = 0; +void LayerStackWidget::onLayerDestroyed(QObject *obj) { + if (obj == _specialLayer) { + _specialLayer = nullptr; + onClose(); + } else if (obj == layer()) { + _layers.pop_back(); + if (auto newLayer = layer()) { + newLayer->parentResized(); + if (!_a_background.animating()) { + newLayer->show(); + } + } else if (!_specialLayer) { + onClose(); + } + fixOrder(); + if (App::wnd()) App::wnd()->setInnerFocus(); + updateLayerBox(); } else { - int32 index = _hidden.indexOf(static_cast(obj)); - if (index >= 0) { - _hidden.removeAt(index); + for (auto i = _layers.begin(), e = _layers.end(); i != e; ++i) { + if (obj == *i) { + _layers.erase(i); + break; + } } } } -BackgroundWidget::~BackgroundWidget() { - if (App::wnd()) App::wnd()->noBox(this); - w->deleteLater(); - for (HiddenLayers::const_iterator i = _hidden.cbegin(), e = _hidden.cend(); i != e; ++i) { - (*i)->deleteLater(); - } +LayerStackWidget::~LayerStackWidget() { + if (App::wnd()) App::wnd()->noLayerStack(this); } MediaPreviewWidget::MediaPreviewWidget(QWidget *parent) : TWidget(parent) diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index c5ba79eb7..6bc69cd73 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -22,24 +22,14 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/boxshadow.h" -class LayeredWidget : public TWidget { +class LayerWidget : public TWidget { Q_OBJECT public: - - virtual void showStep(float64 ms) { - } virtual void parentResized() = 0; - virtual void startHide() { - } - - virtual void setInnerFocus() { - setFocus(); - } - - virtual void resizeEvent(QResizeEvent *e) { - emit resized(); + virtual void showDone() { } + void setInnerFocus(); void mousePressEvent(QMouseEvent *e) { e->accept(); @@ -50,60 +40,91 @@ public: return rect().contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size())); } -signals: +protected: + void resizeEvent(QResizeEvent *e) override { + emit resized(); + } + virtual void doSetInnerFocus() { + setFocus(); + } - void closed(); +signals: + void closed(LayerWidget *layer); void resized(); }; -class BackgroundWidget : public TWidget { +class LayerStackWidget : public TWidget { Q_OBJECT public: - - BackgroundWidget(QWidget *parent, LayeredWidget *w); + LayerStackWidget(QWidget *parent); void showFast(); - void paintEvent(QPaintEvent *e); - void keyPressEvent(QKeyEvent *e); - void mousePressEvent(QMouseEvent *e); - void resizeEvent(QResizeEvent *e); - void updateAdaptiveLayout(); - void replaceInner(LayeredWidget *n); - void showLayerLast(LayeredWidget *n); - - void step_background(float64 ms, bool timer); + void showLayer(LayerWidget *l); + void showSpecialLayer(LayerWidget *l); + void appendLayer(LayerWidget *l); + void prependLayer(LayerWidget *l); bool canSetFocus() const; void setInnerFocus(); bool contentOverlapped(const QRect &globalRect); - ~BackgroundWidget(); - -public slots: - void onClose(); - bool onInnerClose(); - void boxDestroyed(QObject *obj); + + ~LayerStackWidget(); + +protected: + void paintEvent(QPaintEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + +private slots: + void onLayerDestroyed(QObject *obj); + void onLayerClosed(LayerWidget *l); + void onLayerResized(); private: + void clearLayers(); + void initChildLayer(LayerWidget *l); + void activateLayer(LayerWidget *l); + void updateLayerBox(); + void fixOrder(); + void startShow(); void startHide(); + void startAnimation(float64 toOpacity); - LayeredWidget *w; - typedef QList HiddenLayers; - HiddenLayers _hidden; - anim::fvalue a_bg; + void step_background(float64 ms, bool timer); + + LayerWidget *layer() { + return _layers.empty() ? nullptr : _layers.back(); + } + const LayerWidget *layer() const { + return const_cast(this)->layer(); + } + + using Layers = QList; + Layers _layers; + + ChildWidget _specialLayer = { nullptr }; + + class BackgroundWidget; + ChildWidget _background; + + anim::fvalue a_bg, a_layer; Animation _a_background; - bool hiding; + QPixmap _layerCache; + QRect _layerCacheBox; + + bool _hiding = false; - BoxShadow shadow; }; class MediaPreviewWidget : public TWidget { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e49d9f1ed..679c8628a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -535,7 +535,7 @@ void MainWidget::noHider(HistoryHider *destroyed) { _hider = nullptr; if (Adaptive::OneColumn()) { if (_forwardConfirm) { - _forwardConfirm->startHide(); + _forwardConfirm->onClose(); _forwardConfirm = 0; } onHistoryShown(_history->history(), _history->msgId()); @@ -589,9 +589,11 @@ void MainWidget::hiderLayer(HistoryHider *h) { } else { _history->hide(); } - _dialogs->show(); - resizeEvent(0); - _dialogs->showAnimated(Window::SlideDirection::FromLeft, animationParams); + if (_dialogs->isHidden()) { + _dialogs->show(); + resizeEvent(0); + _dialogs->showAnimated(Window::SlideDirection::FromLeft, animationParams); + } App::wnd()->getTitle()->updateBackButton(); } else { _hider->show(); @@ -693,7 +695,7 @@ void MainWidget::offerPeer(PeerId peer) { void MainWidget::onForwardCancel(QObject *obj) { if (!obj || obj == _forwardConfirm) { if (_forwardConfirm) { - if (!obj) _forwardConfirm->startHide(); + if (!obj) _forwardConfirm->onClose(); _forwardConfirm = 0; } if (_hider) _hider->offerPeer(0); @@ -1510,7 +1512,7 @@ void MainWidget::onDownloadPathSettings() { cSetDownloadPathBookmark(QByteArray()); DownloadPathBox *box = new DownloadPathBox(); if (App::wnd() && App::wnd()->settingsWidget()) { - connect(box, SIGNAL(closed()), App::wnd()->settingsWidget(), SLOT(onDownloadPathEdited())); + connect(box, SIGNAL(closed(LayerWidget*)), App::wnd()->settingsWidget(), SLOT(onDownloadPathEdited())); } Ui::showLayer(box); } @@ -2597,12 +2599,14 @@ void MainWidget::showAll() { _dialogs->show(); _history->hide(); } - if (_wideSection) { - _topBar->hide(); - _dialogs->hide(); - } else if (!selectingPeer() && (_overview || _history->peer())) { - _topBar->show(); - _dialogs->hide(); + if (!selectingPeer()) { + if (_wideSection) { + _topBar->hide(); + _dialogs->hide(); + } else if (_overview || _history->peer()) { + _topBar->show(); + _dialogs->hide(); + } } } else { _sideShadow.show(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 0fe9a2283..e95be4cbb 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -799,28 +799,21 @@ void MainWindow::showDocument(DocumentData *doc, HistoryItem *item) { _mediaView->setFocus(); } -void MainWindow::ui_showLayer(LayeredWidget *box, ShowLayerOptions options) { +void MainWindow::ui_showLayer(LayerWidget *box, ShowLayerOptions options) { if (box) { - bool fast = (options.testFlag(ForceFastShowLayer)) || Ui::isLayerShown(); - if (layerBg) { - if (options.testFlag(KeepOtherLayers)) { - if (options.testFlag(ShowAfterOtherLayers)) { - layerBg->showLayerLast(box); - return; - } else { - layerBg->replaceInner(box); - return; - } - } else { - layerBg->onClose(); - layerBg->hide(); - layerBg->deleteLater(); - layerBg = 0; - } + if (!layerBg) { + layerBg = new LayerStackWidget(this); } - - layerBg = new BackgroundWidget(this, box); - if (fast) { + if (options.testFlag(KeepOtherLayers)) { + if (options.testFlag(ShowAfterOtherLayers)) { + layerBg->prependLayer(box); + } else { + layerBg->appendLayer(box); + } + } else { + layerBg->showLayer(box); + } + if (options.testFlag(ForceFastShowLayer)) { layerBg->showFast(); } } else { @@ -829,7 +822,7 @@ void MainWindow::ui_showLayer(LayeredWidget *box, ShowLayerOptions options) { if (options.testFlag(ForceFastShowLayer)) { layerBg->hide(); layerBg->deleteLater(); - layerBg = 0; + layerBg = nullptr; } } hideMediaview(); @@ -922,7 +915,7 @@ void MainWindow::layerHidden() { layerBg->hide(); layerBg->deleteLater(); } - layerBg = 0; + layerBg = nullptr; hideMediaview(); setInnerFocus(); } @@ -1238,13 +1231,13 @@ void MainWindow::noMain(MainWidget *was) { } } -void MainWindow::noBox(BackgroundWidget *was) { +void MainWindow::noLayerStack(LayerStackWidget *was) { if (was == layerBg) { - layerBg = 0; + layerBg = nullptr; } } -void MainWindow::layerFinishedHide(BackgroundWidget *was) { +void MainWindow::layerFinishedHide(LayerStackWidget *was) { if (was == layerBg) { QTimer::singleShot(0, this, SLOT(layerHidden())); } diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 32926621b..96372e3c6 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -31,11 +31,11 @@ class PasscodeWidget; class IntroWidget; class MainWidget; class SettingsWidget; -class BackgroundWidget; -class LayeredWidget; +class LayerStackWidget; +class LayerWidget; namespace Local { - class ClearManager; -} +class ClearManager; +} // namespace Local class ConnectingWidget : public QWidget { Q_OBJECT @@ -192,8 +192,8 @@ public: void noIntro(IntroWidget *was); void noSettings(SettingsWidget *was); void noMain(MainWidget *was); - void noBox(BackgroundWidget *was); - void layerFinishedHide(BackgroundWidget *was); + void noLayerStack(LayerStackWidget *was); + void layerFinishedHide(LayerStackWidget *was); void fixOrder(); @@ -240,7 +240,7 @@ public: return contentOverlapped(QRect(w->mapToGlobal(r.boundingRect().topLeft()), r.boundingRect().size())); } - void ui_showLayer(LayeredWidget *box, ShowLayerOptions options); + void ui_showLayer(LayerWidget *box, ShowLayerOptions options); bool ui_isLayerShown(); bool ui_isMediaViewShown(); void ui_showMediaPreview(DocumentData *document); @@ -317,7 +317,7 @@ private: IntroWidget *intro = nullptr; MainWidget *main = nullptr; SettingsWidget *settings = nullptr; - BackgroundWidget *layerBg = nullptr; + ChildWidget layerBg = { nullptr }; std_::unique_ptr _mediaPreview; QTimer _isActiveTimer; diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index 5c6e2f9f7..b4e590449 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -508,7 +508,7 @@ void CoverWidget::showSetPhotoBox(const QImage &img) { } auto box = new PhotoCropBox(img, _peer); - connect(box, SIGNAL(closed()), this, SLOT(onPhotoUploadStatusChanged())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onPhotoUploadStatusChanged())); Ui::showLayer(box); } diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style new file mode 100644 index 000000000..e9fb441c9 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings.style @@ -0,0 +1,23 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +using "basic.style"; +using "basic_types.style"; + diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp new file mode 100644 index 000000000..281a673d4 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -0,0 +1,26 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#include "stdafx.h" +#include "settings/settings_widget.h" + +namespace Settings { + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_widget.h b/Telegram/SourceFiles/settings/settings_widget.h new file mode 100644 index 000000000..aa345c860 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_widget.h @@ -0,0 +1,25 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#pragma once + +namespace Settings { + +} // namespace Settings diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index 7f0bd6bc7..954273a35 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -1253,7 +1253,7 @@ void SettingsInner::onUpdatePhoto() { return; } PhotoCropBox *box = new PhotoCropBox(img, self()); - connect(box, SIGNAL(closed()), this, SLOT(onPhotoUpdateStart())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onPhotoUpdateStart())); Ui::showLayer(box); } @@ -1374,13 +1374,13 @@ void SettingsInner::onRestartNow() { void SettingsInner::onPasscode() { PasscodeBox *box = new PasscodeBox(); - connect(box, SIGNAL(closed()), this, SLOT(passcodeChanged())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(passcodeChanged())); Ui::showLayer(box); } void SettingsInner::onPasscodeOff() { PasscodeBox *box = new PasscodeBox(true); - connect(box, SIGNAL(closed()), this, SLOT(passcodeChanged())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(passcodeChanged())); Ui::showLayer(box); } @@ -1413,21 +1413,21 @@ void SettingsInner::onReloadPassword(Qt::ApplicationState state) { void SettingsInner::onAutoLock() { AutoLockBox *box = new AutoLockBox(); - connect(box, SIGNAL(closed()), this, SLOT(passcodeChanged())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(passcodeChanged())); Ui::showLayer(box); } #ifndef TDESKTOP_DISABLE_NETWORK_PROXY void SettingsInner::onConnectionType() { ConnectionBox *box = new ConnectionBox(); - connect(box, SIGNAL(closed()), this, SLOT(updateConnectionType()), Qt::QueuedConnection); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(updateConnectionType()), Qt::QueuedConnection); Ui::showLayer(box); } #endif void SettingsInner::onUsername() { UsernameBox *box = new UsernameBox(); - connect(box, SIGNAL(closed()), this, SLOT(usernameChanged())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(usernameChanged())); Ui::showLayer(box); } @@ -1775,7 +1775,7 @@ void SettingsInner::onDontAskDownloadPath() { void SettingsInner::onDownloadPathEdit() { DownloadPathBox *box = new DownloadPathBox(); - connect(box, SIGNAL(closed()), this, SLOT(onDownloadPathEdited())); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onDownloadPathEdited())); Ui::showLayer(box); } diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index bdc4d81ff..5c628fb8d 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -192,9 +192,6 @@ void CountryInput::setText(const QString &newText) { _text = _st.font->elided(newText, width() - _st.textMrg.left() - _st.textMrg.right()); } -CountryInput::~CountryInput() { -} - CountrySelectInner::CountrySelectInner() : TWidget() , _rowHeight(st::countryRowHeight) , _sel(0) @@ -483,13 +480,6 @@ void CountrySelectBox::resizeEvent(QResizeEvent *e) { _topShadow.setGeometry(0, st::boxTitleHeight + _filter.height(), width(), st::lineWidth); } -void CountrySelectBox::hideAll() { - _filter.hide(); - _filterCancel.hide(); - _topShadow.hide(); - ItemListBox::hideAll(); -} - void CountrySelectBox::showAll() { _filter.show(); if (_filter.getLastText().isEmpty()) { @@ -515,6 +505,6 @@ void CountrySelectBox::onFilterUpdate() { _inner.updateFilter(_filter.getLastText()); } -void CountrySelectBox::showDone() { +void CountrySelectBox::doSetInnerFocus() { _filter.setFocus(); } diff --git a/Telegram/SourceFiles/ui/countryinput.h b/Telegram/SourceFiles/ui/countryinput.h index 8e30aeef4..d23e422a3 100644 --- a/Telegram/SourceFiles/ui/countryinput.h +++ b/Telegram/SourceFiles/ui/countryinput.h @@ -34,28 +34,23 @@ class CountryInput : public QWidget { Q_OBJECT public: - CountryInput(QWidget *parent, const style::countryInput &st); - void paintEvent(QPaintEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - - ~CountryInput(); - public slots: - void onChooseCode(const QString &code); bool onChooseCountry(const QString &country); signals: - void codeChanged(const QString &code); -private: +protected: + void paintEvent(QPaintEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; +private: void setText(const QString &newText); QPixmap _arrow; @@ -72,13 +67,7 @@ class CountrySelectInner : public TWidget { Q_OBJECT public: - CountrySelectInner(); - void paintEvent(QPaintEvent *e); - void enterEvent(QEvent *e); - void leaveEvent(QEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); void updateFilter(QString filter = QString()); @@ -86,20 +75,24 @@ public: void selectSkipPage(int32 h, int32 dir); void chooseCountry(); - + void refresh(); signals: - void countryChosen(const QString &iso); void mustScrollTo(int ymin, int ymax); public slots: - void updateSel(); -private: +protected: + void paintEvent(QPaintEvent *e) override; + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; +private: void updateSelectedRow(); int32 _rowHeight; @@ -109,43 +102,36 @@ private: bool _mouseSel; QPoint _lastMousePos; + }; class CountrySelectBox : public ItemListBox { Q_OBJECT public: - CountrySelectBox(); - void keyPressEvent(QKeyEvent *e); - void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); - - void setInnerFocus() { - _filter.setFocus(); - } signals: - void countryChosen(const QString &iso); public slots: - void onFilterUpdate(); void onFilterCancel(); void onSubmit(); protected: + void keyPressEvent(QKeyEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; - void showDone(); - void hideAll(); - void showAll(); + void doSetInnerFocus() override; + void showAll() override; private: - CountrySelectInner _inner; InputField _filter; IconedButton _filterCancel; ScrollableBoxShadow _topShadow; + }; diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index fe41c5951..554819954 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -33,6 +33,7 @@ '<(src_loc)/media/view/mediaview.style', '<(src_loc)/overview/overview.style', '<(src_loc)/profile/profile.style', + '<(src_loc)/settings/settings.style', '<(src_loc)/ui/widgets/widgets.style', ], 'qrc_files': [ @@ -329,6 +330,8 @@ '<(src_loc)/serialize/serialize_common.h', '<(src_loc)/serialize/serialize_document.cpp', '<(src_loc)/serialize/serialize_document.h', + '<(src_loc)/settings/settings_widget.cpp', + '<(src_loc)/settings/settings_widget.h', '<(src_loc)/ui/buttons/history_down_button.cpp', '<(src_loc)/ui/buttons/history_down_button.h', '<(src_loc)/ui/buttons/icon_button.cpp',