Forward bar and unread counter added to top bar in OneColumn layout.

This commit is contained in:
John Preston 2016-11-06 20:23:13 +03:00
parent d12177befd
commit b3d1602354
25 changed files with 164 additions and 30 deletions

View File

@ -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);

View File

@ -143,6 +143,8 @@ dialogsVerifiedIconFgActive: dialogsVerifiedIconFgOver;
dialogsSendingIconFgActive: dialogsSendingIconFgOver;
dialogsSentIconFgActive: dialogsSentIconFgOver;
dialogsForwardFg: #ffffff;
// history
topBarBg: windowBg;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 354 B

After

Width:  |  Height:  |  Size: 176 B

View File

@ -115,6 +115,7 @@ dialogsVerifiedIconBgActive: dialogsVerifiedIconBgOver;
dialogsVerifiedIconFgActive: dialogsVerifiedIconFgOver;
dialogsSendingIconFgActive: dialogsSendingIconFgOver;
dialogsSentIconFgActive: dialogsSentIconFgOver;
dialogsForwardFg: #ffffff;
topBarBg: windowBg;
emojiPanBg: windowBg;
emojiPanCategories: #f7f7f7; // windowBg;

View File

@ -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() {

View File

@ -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;

View File

@ -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 &params) {
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);
}

View File

@ -253,6 +253,7 @@ public:
return true;
}
void showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams &params);
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<Ui::IconButton> _forwardCancel = { nullptr };
ChildWidget<Ui::IconButton> _mainMenuToggle;
ChildWidget<Ui::DropdownMenu> _mainMenu = { nullptr };
ChildWidget<FlatInput> _filter;

View File

@ -666,6 +666,8 @@ struct Data {
base::Observable<void> LocalPasscodeChanged;
base::Observable<HistoryItem*> ItemRemoved;
base::Observable<void> UnreadCounterUpdate;
base::Observable<void> PeerChooseCancel;
};
@ -781,5 +783,7 @@ DefineVar(Global, bool, LocalPasscode);
DefineRefVar(Global, base::Observable<void>, LocalPasscodeChanged);
DefineRefVar(Global, base::Observable<HistoryItem*>, ItemRemoved);
DefineRefVar(Global, base::Observable<void>, UnreadCounterUpdate);
DefineRefVar(Global, base::Observable<void>, PeerChooseCancel);
} // namespace Global

View File

@ -355,6 +355,8 @@ DeclareVar(bool, LocalPasscode);
DeclareRefVar(base::Observable<void>, LocalPasscodeChanged);
DeclareRefVar(base::Observable<HistoryItem*>, ItemRemoved);
DeclareRefVar(base::Observable<void>, UnreadCounterUpdate);
DeclareRefVar(base::Observable<void>, PeerChooseCancel);
} // namespace Global

View File

@ -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 {

View File

@ -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();

View File

@ -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 {

View File

@ -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();

View File

@ -103,6 +103,7 @@ MainWindow::MainWindow() {
Notify::unreadCounterUpdated();
}
});
subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); });
resize(st::windowDefaultWidth, st::windowDefaultHeight);

View File

@ -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();

View File

@ -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() {

View File

@ -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;

View File

@ -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));

View File

@ -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;

View File

@ -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;
};

View File

@ -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() {

View File

@ -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<TWidget> _membersShowArea = { nullptr };
int _unreadCounterSubscription = 0;
};
} // namespace Window

View File

@ -82,6 +82,11 @@ notifySendReply: IconButton {
iconPositionDown: point(0px, 1px);
}
titleUnreadCounterTop: 5px;
titleUnreadCounterRight: 35px;
// Windows specific title
titleHeight: 21px;
titleButtonMinimize: IconButton {
width: 24px;