diff --git a/Telegram/Resources/basic.style b/Telegram/Resources/basic.style index 234e9f2dcf..152e9870a6 100644 --- a/Telegram/Resources/basic.style +++ b/Telegram/Resources/basic.style @@ -817,6 +817,7 @@ contactsScroll: flatScroll(boxScroll) { simpleCloseIcon: icon {{ "simple_close", #c7c7c7 }}; simpleCloseIconOver: icon {{ "simple_close", #a3a3a3 }}; +dialogsForwardCancelIcon: icon {{ "simple_close", dialogsForwardFg }}; boxPhotoPadding: margins(28px, 28px, 28px, 18px); boxPhotoCompressedPadding: margins(0px, 2px, 0px, 22px); diff --git a/Telegram/Resources/colors.palette b/Telegram/Resources/colors.palette index 24ac18d9f9..dc3c4a8986 100644 --- a/Telegram/Resources/colors.palette +++ b/Telegram/Resources/colors.palette @@ -143,6 +143,8 @@ dialogsVerifiedIconFgActive: dialogsVerifiedIconFgOver; dialogsSendingIconFgActive: dialogsSendingIconFgOver; dialogsSentIconFgActive: dialogsSentIconFgOver; +dialogsForwardFg: #ffffff; + // history topBarBg: windowBg; diff --git a/Telegram/Resources/icons/simple_close.png b/Telegram/Resources/icons/simple_close.png index 07e1c0c58f..10f8b030e8 100644 Binary files a/Telegram/Resources/icons/simple_close.png and b/Telegram/Resources/icons/simple_close.png differ diff --git a/Telegram/Resources/icons/simple_close@2x.png b/Telegram/Resources/icons/simple_close@2x.png index 7825b270a1..a53c4af643 100644 Binary files a/Telegram/Resources/icons/simple_close@2x.png and b/Telegram/Resources/icons/simple_close@2x.png differ diff --git a/Telegram/Resources/sample.tdesktop-theme b/Telegram/Resources/sample.tdesktop-theme index 56cddb35ce..abd4bb4026 100644 --- a/Telegram/Resources/sample.tdesktop-theme +++ b/Telegram/Resources/sample.tdesktop-theme @@ -115,6 +115,7 @@ dialogsVerifiedIconBgActive: dialogsVerifiedIconBgOver; dialogsVerifiedIconFgActive: dialogsVerifiedIconFgOver; dialogsSendingIconFgActive: dialogsSendingIconFgOver; dialogsSentIconFgActive: dialogsSentIconFgOver; +dialogsForwardFg: #ffffff; topBarBg: windowBg; emojiPanBg: windowBg; emojiPanCategories: #f7f7f7; // windowBg; diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 159a844b7d..42953122cf 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -932,9 +932,7 @@ void AppClass::call_handleHistoryUpdate() { } void AppClass::call_handleUnreadCounterUpdate() { - if (auto w = App::wnd()) { - w->updateUnreadCounter(); - } + Global::RefUnreadCounterUpdate().notify(true); } void AppClass::call_handleFileDialogQueue() { diff --git a/Telegram/SourceFiles/dialogs/dialogs.style b/Telegram/SourceFiles/dialogs/dialogs.style index 38f8fdd2ec..219b91c248 100644 --- a/Telegram/SourceFiles/dialogs/dialogs.style +++ b/Telegram/SourceFiles/dialogs/dialogs.style @@ -184,3 +184,19 @@ dialogsUpdateButton: flatButton { font: semiboldFont; overFont: semiboldFont; } + +dialogsForwardHeight: 32px; +dialogsForwardTextLeft: 35px; +dialogsForwardTextTop: 6px; +dialogsForwardCancel: IconButton { + width: 34px; + height: dialogsForwardHeight; + + icon: dialogsForwardCancelIcon; + iconOver: dialogsForwardCancelIcon; + + iconPosition: point(12px, 11px); + iconPositionDown: point(12px, 11px); +} +dialogsForwardFont: semiboldFont; +dialogsForwardBg: windowActiveFill; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 48ae1070c5..ba87b6f030 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -1695,6 +1695,8 @@ DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent) onCheckUpdateStatus(); #endif // !TDESKTOP_DISABLE_AUTOUPDATE + subscribe(Adaptive::Changed(), [this] { updateForwardBar(); }); + _cancelSearch->setClickedCallback([this] { onCancelSearch(); }); _lockUnlock->setVisible(Global::LocalPasscode()); subscribe(Global::RefLocalPasscodeChanged(), [this] { updateLockUnlockVisibility(); }); @@ -1767,17 +1769,24 @@ void DialogsWidget::dialogsToUp() { } } +void DialogsWidget::showFast() { + show(); + updateForwardBar(); +} + void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams ¶ms) { if (App::app()) App::app()->mtpPause(); _cacheUnder = params.oldContentCache; show(); + updateForwardBar(); _cacheOver = App::main()->grabForShowAnimation(params); _a_show.stop(); _scroll->hide(); _mainMenuToggle->hide(); + if (_forwardCancel) _forwardCancel->hide(); _filter->hide(); _cancelSearch->hide(); _lockUnlock->hide(); @@ -1809,6 +1818,7 @@ void DialogsWidget::step_show(float64 ms, bool timer) { _scroll->show(); _mainMenuToggle->show(); + if (_forwardCancel) _forwardCancel->show(); _filter->show(); updateLockUnlockVisibility(); _a_show.stop(); @@ -2378,20 +2388,26 @@ void DialogsWidget::updateLockUnlockVisibility() { } void DialogsWidget::updateControlsGeometry() { + auto filterTop = 0; + if (_forwardCancel) { + _forwardCancel->moveToLeft(0, filterTop); + filterTop += st::dialogsForwardHeight; + } auto filterLeft = st::dialogsFilterPadding.x() * 2 + _mainMenuToggle->width(); auto filterWidth = width() - 2 * st::dialogsFilterPadding.x(); filterWidth -= st::dialogsFilterPadding.x() + _mainMenuToggle->width(); if (Global::LocalPasscode()) { filterWidth -= st::dialogsFilterPadding.x() + _lockUnlock->width(); } - _filter->setGeometryToLeft(filterLeft, st::dialogsFilterPadding.y(), filterWidth, _filter->height()); + filterTop += st::dialogsFilterPadding.y(); + _filter->setGeometryToLeft(filterLeft, filterTop, filterWidth, _filter->height()); _mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), _filter->y()); _lockUnlock->moveToRight(st::dialogsFilterPadding.x(), _filter->y()); _cancelSearch->moveToLeft(filterLeft + filterWidth - _cancelSearch->width(), _filter->y()); auto addToScroll = App::main() ? App::main()->contentScrollAddToY() : 0; auto newScrollTop = _scroll->scrollTop() + addToScroll; - auto scrollTop = _filter->height() + 2 * st::dialogsFilterPadding.y(); + auto scrollTop = filterTop + _filter->height() + st::dialogsFilterPadding.y(); auto scrollHeight = height() - scrollTop; if (_updateTelegram) { auto updateHeight = _updateTelegram->height(); @@ -2414,6 +2430,23 @@ void DialogsWidget::updateMainMenuGeometry() { _mainMenu->moveToLeft(st::dialogsMenuPosition.x(), st::dialogsMenuPosition.y()); } +void DialogsWidget::updateForwardBar() { + auto selecting = App::main()->selectingPeer(); + auto oneColumnSelecting = (Adaptive::OneColumn() && selecting); + if (!oneColumnSelecting == !_forwardCancel) { + return; + } + if (oneColumnSelecting) { + _forwardCancel.create(this, st::dialogsForwardCancel); + _forwardCancel->setClickedCallback([] { Global::RefPeerChooseCancel().notify(true); }); + if (!_a_show.animating()) _forwardCancel->show(); + } else { + _forwardCancel.destroyDelayed(); + } + updateControlsGeometry(); + update(); +} + void DialogsWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { e->ignore(); @@ -2464,11 +2497,19 @@ void DialogsWidget::paintEvent(QPaintEvent *e) { st::slideShadow.fill(p, QRect(a_coordOver.current() - st::slideShadow.width(), 0, st::slideShadow.width(), _cacheOver.height() / retina)); return; } - QRect above(0, 0, width(), _scroll->y()); + auto aboveTop = 0; + if (_forwardCancel) { + p.fillRect(0, aboveTop, width(), st::dialogsForwardHeight, st::dialogsForwardBg); + p.setPen(st::dialogsForwardFg); + p.setFont(st::dialogsForwardFont); + p.drawTextLeft(st::dialogsForwardTextLeft, st::dialogsForwardTextTop, width(), lang(lng_forward_choose)); + aboveTop += st::dialogsForwardHeight; + } + auto above = QRect(0, aboveTop, width(), _scroll->y()); if (above.intersects(r)) { p.fillRect(above.intersected(r), st::dialogsBg); } - QRect below(0, _scroll->y() + qMin(_scroll->height(), _inner->height()), width(), height()); + auto below = QRect(0, _scroll->y() + qMin(_scroll->height(), _inner->height()), width(), height()); if (below.intersects(r)) { p.fillRect(below.intersected(r), st::dialogsBg); } diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index f2f735213b..cac76a09b4 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -253,6 +253,7 @@ public: return true; } void showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams ¶ms); + void showFast(); void step_show(float64 ms, bool timer); void destroyData(); @@ -307,6 +308,7 @@ private: void updateLockUnlockVisibility(); void updateControlsGeometry(); void updateMainMenuGeometry(); + void updateForwardBar(); bool _dragInScroll = false; bool _dragForward = false; @@ -325,6 +327,7 @@ private: mtpRequestId _dialogsRequest = 0; mtpRequestId _contactsRequest = 0; + ChildWidget _forwardCancel = { nullptr }; ChildWidget _mainMenuToggle; ChildWidget _mainMenu = { nullptr }; ChildWidget _filter; diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 8457a07758..6a8a88d832 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -666,6 +666,8 @@ struct Data { base::Observable LocalPasscodeChanged; base::Observable ItemRemoved; + base::Observable UnreadCounterUpdate; + base::Observable PeerChooseCancel; }; @@ -781,5 +783,7 @@ DefineVar(Global, bool, LocalPasscode); DefineRefVar(Global, base::Observable, LocalPasscodeChanged); DefineRefVar(Global, base::Observable, ItemRemoved); +DefineRefVar(Global, base::Observable, UnreadCounterUpdate); +DefineRefVar(Global, base::Observable, PeerChooseCancel); } // namespace Global diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index dc3eaed73a..b95f128f47 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -355,6 +355,8 @@ DeclareVar(bool, LocalPasscode); DeclareRefVar(base::Observable, LocalPasscodeChanged); DeclareRefVar(base::Observable, ItemRemoved); +DeclareRefVar(base::Observable, UnreadCounterUpdate); +DeclareRefVar(base::Observable, PeerChooseCancel); } // namespace Global diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index d4c86564fe..acc13358f0 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2701,6 +2701,7 @@ HistoryHider::HistoryHider(MainWidget *parent, const QString &url, const QString void HistoryHider::init() { connect(_send, SIGNAL(clicked()), this, SLOT(forward())); connect(_cancel, SIGNAL(clicked()), this, SLOT(startHide())); + subscribe(Global::RefPeerChooseCancel(), [this] { startHide(); }); _chooseWidth = st::forwardFont->width(lang(_botAndQuery.isEmpty() ? lng_forward_choose : lng_inline_switch_choose)); @@ -6240,7 +6241,7 @@ void HistoryWidget::onForwardHere() { App::forward(_peer->id, ForwardContextMessage); } -void HistoryWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { +bool HistoryWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { if (_a_show.animating()) { int retina = cIntRetinaFactor(); if (a_coordOver.current() > 0) { @@ -6252,10 +6253,10 @@ void HistoryWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { p.drawPixmap(QRect(a_coordOver.current(), 0, _cacheOver.width() / retina, st::topBarHeight), _cacheOver, QRect(0, 0, _cacheOver.width(), st::topBarHeight * retina)); p.setOpacity(a_progress.current()); st::slideShadow.fill(p, QRect(a_coordOver.current() - st::slideShadow.width(), 0, st::slideShadow.width(), st::topBarHeight)); - return; + return false; } - if (!_history) return; + if (!_history) return false; int increaseLeft = (Adaptive::OneColumn() || !App::main()->stackIsEmpty()) ? (st::topBarArrowPadding.left() - st::topBarArrowPadding.right()) : 0; decreaseWidth += increaseLeft; @@ -6275,7 +6276,9 @@ void HistoryWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { if (Adaptive::OneColumn() || !App::main()->stackIsEmpty()) { p.setOpacity(st::topBarForwardAlpha + (1 - st::topBarForwardAlpha) * over); st::topBarBackward.paint(p, (st::topBarArrowPadding.left() - st::topBarBackward.width()) / 2, (st::topBarHeight - st::topBarBackward.height()) / 2, width()); + p.setOpacity(1.); } + return true; } QRect HistoryWidget::getMembersShowAreaGeometry() const { diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 45536b0360..c479a62510 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -441,7 +441,7 @@ private: }; -class HistoryHider : public TWidget { +class HistoryHider : public TWidget, private base::Subscriber { Q_OBJECT public: @@ -559,7 +559,7 @@ public: void updateTopBarSelection(); - void paintTopBar(Painter &p, float64 over, int32 decreaseWidth); + bool paintTopBar(Painter &p, float64 over, int32 decreaseWidth); QRect getMembersShowAreaGeometry() const; void setMembersShowAreaActive(bool active); void topBarClick(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index a2bf332d29..3ae0590642 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2264,7 +2264,7 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show if (!animationParams.oldContentCache.isNull()) { _dialogs->showAnimated(back ? Window::SlideDirection::FromLeft : Window::SlideDirection::FromRight, animationParams); } else { - _dialogs->show(); + _dialogs->showFast(); } } } else { @@ -2820,7 +2820,7 @@ void MainWidget::showAll() { } } if (selectingPeer()) { - _dialogs->show(); + _dialogs->showFast(); _history->hide(); if (_overview) _overview->hide(); if (_wideSection) _wideSection->hide(); @@ -2833,7 +2833,7 @@ void MainWidget::showAll() { _history->show(); _history->updateControlsGeometry(); } else { - _dialogs->show(); + _dialogs->showFast(); _history->hide(); } if (!selectingPeer()) { @@ -2854,7 +2854,7 @@ void MainWidget::showAll() { _forwardConfirm = 0; } } - _dialogs->show(); + _dialogs->showFast(); if (_overview) { _overview->show(); } else if (_wideSection) { @@ -2972,12 +2972,13 @@ bool MainWidget::needBackButton() { return _overview || _wideSection || _history->peer(); } -void MainWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { +bool MainWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { if (_overview) { - _overview->paintTopBar(p, over, decreaseWidth); + return _overview->paintTopBar(p, over, decreaseWidth); } else if (!_wideSection) { - _history->paintTopBar(p, over, decreaseWidth); + return _history->paintTopBar(p, over, decreaseWidth); } + return false; } QRect MainWidget::getMembersShowAreaGeometry() const { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 5da1b0b7e2..1c8a279a5a 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -144,7 +144,7 @@ public: bool needBackButton(); // Temporary methods, while top bar was not done inside HistoryWidget / OverviewWidget. - void paintTopBar(Painter &p, float64 over, int32 decreaseWidth); + bool paintTopBar(Painter &p, float64 over, int32 decreaseWidth); QRect getMembersShowAreaGeometry() const; void setMembersShowAreaActive(bool active); Window::TopBarWidget *topBar(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 37a9c943c1..da17f3560c 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -103,6 +103,7 @@ MainWindow::MainWindow() { Notify::unreadCounterUpdated(); } }); + subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); }); resize(st::windowDefaultWidth, st::windowDefaultHeight); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index e9f5995e4e..b1d8fc839f 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -144,8 +144,6 @@ public: bool isActive(bool cached = true) const; void hideMediaview(); - void updateUnreadCounter(); - QImage iconWithCounter(int size, int count, const style::color &bg, const style::color &fg, bool smallIcon); bool contentOverlapped(const QRect &globalRect); @@ -217,6 +215,7 @@ private slots: void onWindowActiveChanged(); private: + void updateUnreadCounter(); void showConnecting(const QString &text, const QString &reconnect = QString()); void hideConnecting(); diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index ffa8c8da3d..7b67d75443 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -1969,7 +1969,7 @@ void OverviewWidget::scrollReset() { _scroll.scrollToY((type() == OverviewMusicFiles || type() == OverviewVoiceFiles) ? _scroll.scrollTopMax() : 0); } -void OverviewWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { +bool OverviewWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) { if (_a_show.animating()) { int retina = cIntRetinaFactor(); if (a_coordOver.current() > 0) { @@ -1981,13 +1981,15 @@ void OverviewWidget::paintTopBar(Painter &p, float64 over, int32 decreaseWidth) p.drawPixmap(QRect(a_coordOver.current(), 0, _cacheOver.width() / retina, st::topBarHeight), _cacheOver, QRect(0, 0, _cacheOver.width(), st::topBarHeight * retina)); p.setOpacity(a_progress.current()); st::slideShadow.fill(p, QRect(a_coordOver.current() - st::slideShadow.width(), 0, st::slideShadow.width(), st::topBarHeight)); - return; + return false; } p.setOpacity(st::topBarBackAlpha + (1 - st::topBarBackAlpha) * over); st::topBarBack.paint(p, (st::topBarArrowPadding.left() - st::topBarBack.width()) / 2, (st::topBarHeight - st::topBarBack.height()) / 2, width()); p.setFont(st::topBarBackFont); p.setPen(st::topBarBackColor); p.drawText(st::topBarArrowPadding.left(), (st::topBarHeight - st::topBarBackFont->height) / 2 + st::topBarBackFont->ascent, _header); + p.setOpacity(1.); + return true; } void OverviewWidget::topBarClick() { diff --git a/Telegram/SourceFiles/overviewwidget.h b/Telegram/SourceFiles/overviewwidget.h index 9b81e2ee7b..aebbe33cb3 100644 --- a/Telegram/SourceFiles/overviewwidget.h +++ b/Telegram/SourceFiles/overviewwidget.h @@ -279,7 +279,7 @@ public: void scrollBy(int32 add); void scrollReset(); - void paintTopBar(Painter &p, float64 over, int32 decreaseWidth); + bool paintTopBar(Painter &p, float64 over, int32 decreaseWidth); void topBarClick(); PeerData *peer() const; diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index e328e4dcbb..cef2dfd05e 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -724,8 +724,8 @@ void MainWindow::psUpdateWorkmode() { } void MainWindow::psUpdateCounter() { - int32 counter = App::histories().unreadBadge(); - bool muted = App::histories().unreadOnlyMuted(); + auto counter = App::histories().unreadBadge(); + auto muted = App::histories().unreadOnlyMuted(); auto iconSizeSmall = QSize(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); auto iconSizeBig = QSize(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); diff --git a/Telegram/SourceFiles/profile/profile.style b/Telegram/SourceFiles/profile/profile.style index 80c306a07e..5c7ffca410 100644 --- a/Telegram/SourceFiles/profile/profile.style +++ b/Telegram/SourceFiles/profile/profile.style @@ -27,7 +27,7 @@ profileTopBarHeight: topBarHeight; profileTopBarBackIconPosition: point(12px, 20px); profileTopBarBackFont: font(14px); profileTopBarBackFg: #1485c2; -profileTopBarBackPosition: point(32px, 17px); +profileTopBarBackPosition: point(39px, 17px); profileFixedBarButton: topBarButton; profileMarginTop: 13px; diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp index c936b22969..584b480d77 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp @@ -22,19 +22,24 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "profile/profile_fixed_bar.h" #include "styles/style_profile.h" +#include "styles/style_window.h" #include "ui/buttons/round_button.h" #include "lang.h" #include "mainwidget.h" #include "boxes/addcontactbox.h" #include "boxes/confirmbox.h" #include "observer_peer.h" +#include "window/top_bar_widget.h" namespace Profile { -class BackButton final : public Button { +class BackButton final : public Button, private base::Subscriber { public: BackButton(QWidget *parent) : Button(parent) { setCursor(style::cur_pointer); + + subscribe(Adaptive::Changed(), [this] { updateAdaptiveLayout(); }); + updateAdaptiveLayout(); } protected: @@ -50,6 +55,8 @@ protected: p.setFont(st::profileTopBarBackFont); p.setPen(st::profileTopBarBackFg); p.drawTextLeft(st::profileTopBarBackPosition.x(), st::profileTopBarBackPosition.y(), width(), lang(lng_menu_back)); + + Window::TopBarWidget::paintUnreadCounter(p, width()); } void onStateChanged(int oldState, ButtonStateChangeSource source) override { if ((_state & Button::StateDown) && !(oldState & Button::StateDown)) { @@ -58,6 +65,17 @@ protected: } private: + void updateAdaptiveLayout() { + if (!Adaptive::OneColumn()) { + unsubscribe(base::take(_unreadCounterSubscription)); + } else if (!_unreadCounterSubscription) { + _unreadCounterSubscription = subscribe(Global::RefUnreadCounterUpdate(), [this] { + rtlupdate(0, 0, st::titleUnreadCounterRight, st::titleUnreadCounterTop); + }); + } + } + + int _unreadCounterSubscription = 0; }; diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 6ba1389814..f58b25a747 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "window/top_bar_widget.h" #include "styles/style_history.h" +#include "styles/style_window.h" #include "boxes/addcontactbox.h" #include "boxes/confirmbox.h" #include "mainwidget.h" @@ -33,6 +34,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/buttons/icon_button.h" #include "ui/widgets/dropdown_menu.h" #include "ui/flatbutton.h" +#include "dialogs/dialogs_layout.h" namespace Window { @@ -57,6 +59,11 @@ TopBarWidget::TopBarWidget(MainWidget *w) : TWidget(w) _menuToggle->setClickedCallback([this] { showMenu(); }); subscribe(Adaptive::Changed(), [this]() { updateAdaptiveLayout(); }); + if (Adaptive::OneColumn()) { + _unreadCounterSubscription = subscribe(Global::RefUnreadCounterUpdate(), [this] { + rtlupdate(0, 0, st::titleUnreadCounterRight, st::titleUnreadCounterTop); + }); + } setCursor(style::cur_pointer); showAll(); @@ -171,8 +178,27 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { if (!_search->isHidden()) { decreaseWidth += _search->width(); } - main()->paintTopBar(p, a_over.current(), decreaseWidth); + auto paintCounter = main()->paintTopBar(p, a_over.current(), decreaseWidth); p.restore(); + + if (paintCounter) { + paintUnreadCounter(p, width()); + } + } +} + +void TopBarWidget::paintUnreadCounter(Painter &p, int outerWidth) { + if (!Adaptive::OneColumn()) { + return; + } + if (auto counter = App::histories().unreadBadge()) { + auto counterText = (counter > 99) ? qsl("..%1").arg(counter % 100) : QString::number(counter); + Dialogs::Layout::UnreadBadgeStyle unreadSt; + unreadSt.muted = App::histories().unreadOnlyMuted(); + auto unreadRight = st::titleUnreadCounterRight; + if (rtl()) unreadRight = outerWidth - st::titleUnreadCounterRight; + auto unreadTop = st::titleUnreadCounterTop; + Dialogs::Layout::paintUnreadCount(p, counterText, unreadRight, unreadTop, unreadSt); } } @@ -316,6 +342,13 @@ void TopBarWidget::showSelected(uint32 selCount, bool canDelete) { void TopBarWidget::updateAdaptiveLayout() { updateMembersShowArea(); showAll(); + if (!Adaptive::OneColumn()) { + unsubscribe(base::take(_unreadCounterSubscription)); + } else if (!_unreadCounterSubscription) { + _unreadCounterSubscription = subscribe(Global::RefUnreadCounterUpdate(), [this] { + rtlupdate(0, 0, st::titleUnreadCounterRight, st::titleUnreadCounterTop); + }); + } } Ui::RoundButton *TopBarWidget::mediaTypeButton() { diff --git a/Telegram/SourceFiles/window/top_bar_widget.h b/Telegram/SourceFiles/window/top_bar_widget.h index 9a133a9ec6..5fdd48fefc 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.h +++ b/Telegram/SourceFiles/window/top_bar_widget.h @@ -56,6 +56,8 @@ public: Ui::RoundButton *mediaTypeButton(); + static void paintUnreadCounter(Painter &p, int outerWidth); + protected: bool eventFilter(QObject *obj, QEvent *e) override; @@ -94,6 +96,8 @@ private: ChildWidget _membersShowArea = { nullptr }; + int _unreadCounterSubscription = 0; + }; } // namespace Window diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index 50bd74cad4..4c130b5711 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -82,6 +82,11 @@ notifySendReply: IconButton { iconPositionDown: point(0px, 1px); } +titleUnreadCounterTop: 5px; +titleUnreadCounterRight: 35px; + +// Windows specific title + titleHeight: 21px; titleButtonMinimize: IconButton { width: 24px;