Fix important switch hiding in folders.

This commit is contained in:
John Preston 2019-04-25 12:59:57 +04:00
parent 48ad171a29
commit 430a3c2cec
2 changed files with 25 additions and 19 deletions

View File

@ -86,6 +86,7 @@ InnerWidget::InnerWidget(
if (Global::DialogsModeEnabled()) { if (Global::DialogsModeEnabled()) {
_importantSwitch = std::make_unique<ImportantSwitch>(); _importantSwitch = std::make_unique<ImportantSwitch>();
_mode = Global::DialogsMode();
} }
connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact())); connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact()));
_cancelSearchInChat->setClickedCallback([=] { cancelSearchInChat(); }); _cancelSearchInChat->setClickedCallback([=] { cancelSearchInChat(); });
@ -224,8 +225,12 @@ void InnerWidget::handleChatMigration(not_null<ChatData*> chat) {
} }
} }
bool InnerWidget::importantSwitchShown() const {
return !_openedFolder && _importantSwitch;
}
int InnerWidget::dialogsOffset() const { int InnerWidget::dialogsOffset() const {
return _importantSwitch return importantSwitchShown()
? st::dialogsImportantBarHeight ? st::dialogsImportantBarHeight
: 0; : 0;
} }
@ -279,6 +284,7 @@ void InnerWidget::changeOpenedFolder(Data::Folder *folder) {
//const auto lastMousePosition = _lastMousePosition; //const auto lastMousePosition = _lastMousePosition;
clearSelection(); clearSelection();
_openedFolder = folder; _openedFolder = folder;
_mode = _openedFolder ? Mode::All : Global::DialogsMode();
refresh(); refresh();
// This doesn't work, because we clear selection in leaveEvent on hide. // This doesn't work, because we clear selection in leaveEvent on hide.
//if (mouseSelection && lastMousePosition) { //if (mouseSelection && lastMousePosition) {
@ -302,9 +308,9 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
auto ms = crl::now(); auto ms = crl::now();
if (_state == WidgetState::Default) { if (_state == WidgetState::Default) {
auto rows = shownDialogs(); auto rows = shownDialogs();
if (!_openedFolder && _importantSwitch) { if (importantSwitchShown()) {
auto selected = isPressed() ? _importantSwitchPressed : _importantSwitchSelected; auto selected = isPressed() ? _importantSwitchPressed : _importantSwitchSelected;
Layout::paintImportantSwitch(p, Global::DialogsMode(), fullWidth, selected); Layout::paintImportantSwitch(p, _mode, fullWidth, selected);
dialogsClip.translate(0, -st::dialogsImportantBarHeight); dialogsClip.translate(0, -st::dialogsImportantBarHeight);
p.translate(0, st::dialogsImportantBarHeight); p.translate(0, st::dialogsImportantBarHeight);
} }
@ -782,8 +788,7 @@ void InnerWidget::selectByMouse(QPoint globalPosition) {
if (_state == WidgetState::Default) { if (_state == WidgetState::Default) {
const auto switchTop = 0; const auto switchTop = 0;
const auto switchBottom = dialogsOffset(); const auto switchBottom = dialogsOffset();
const auto importantSwitchSelected = _importantSwitch const auto importantSwitchSelected = importantSwitchShown()
&& !_openedFolder
&& (mouseY >= switchTop) && (mouseY >= switchTop)
&& (mouseY < switchBottom); && (mouseY < switchBottom);
const auto selected = importantSwitchSelected const auto selected = importantSwitchSelected
@ -888,7 +893,7 @@ void InnerWidget::mousePressEvent(QMouseEvent *e) {
}); });
} else if (base::in_range(_filteredPressed, 0, _filterResults.size())) { } else if (base::in_range(_filteredPressed, 0, _filterResults.size())) {
const auto row = _filterResults[_filteredPressed]; const auto row = _filterResults[_filteredPressed];
const auto list = Global::DialogsMode(); const auto list = _mode;
row->addRipple( row->addRipple(
e->pos() - QPoint(0, filteredOffset() + _filteredPressed * st::dialogsRowHeight), e->pos() - QPoint(0, filteredOffset() + _filteredPressed * st::dialogsRowHeight),
QSize(width(), st::dialogsRowHeight), QSize(width(), st::dialogsRowHeight),
@ -1286,10 +1291,10 @@ void InnerWidget::refreshDialog(Key key) {
} }
const auto result = session().data().refreshChatListEntry(key); const auto result = session().data().refreshChatListEntry(key);
const auto changed = (Global::DialogsMode() == Mode::Important) const auto changed = (_mode == Mode::Important)
? result.importantChanged ? result.importantChanged
: result.changed; : result.changed;
const auto moved = (Global::DialogsMode() == Mode::Important) const auto moved = (_mode == Mode::Important)
? result.importantMoved ? result.importantMoved
: result.moved; : result.moved;
@ -1346,7 +1351,7 @@ void InnerWidget::repaintDialogRow(
Mode list, Mode list,
not_null<Row*> row) { not_null<Row*> row) {
if (_state == WidgetState::Default) { if (_state == WidgetState::Default) {
if (Global::DialogsMode() == list) { if (_mode == list) {
auto position = row->pos(); auto position = row->pos();
auto top = dialogsOffset(); auto top = dialogsOffset();
if (base::in_range(position, 0, _pinnedRows.size())) { if (base::in_range(position, 0, _pinnedRows.size())) {
@ -1476,10 +1481,10 @@ void InnerWidget::updateSelectedRow(Key key) {
if (_state == WidgetState::Default) { if (_state == WidgetState::Default) {
if (key) { if (key) {
const auto entry = key.entry(); const auto entry = key.entry();
if (!entry->inChatList(Global::DialogsMode())) { if (!entry->inChatList(_mode)) {
return; return;
} }
auto position = entry->posInChatList(Global::DialogsMode()); auto position = entry->posInChatList(_mode);
auto top = dialogsOffset(); auto top = dialogsOffset();
if (base::in_range(position, 0, _pinnedRows.size())) { if (base::in_range(position, 0, _pinnedRows.size())) {
top += qRound(_pinnedRows[position].yadd.current()); top += qRound(_pinnedRows[position].yadd.current());
@ -1511,8 +1516,7 @@ void InnerWidget::updateSelectedRow(Key key) {
} }
not_null<IndexedList*> InnerWidget::shownDialogs() const { not_null<IndexedList*> InnerWidget::shownDialogs() const {
const auto mode = Global::DialogsMode(); return session().data().chatsList(_openedFolder)->indexed(_mode);
return session().data().chatsList(_openedFolder)->indexed(mode);
} }
void InnerWidget::leaveEventHook(QEvent *e) { void InnerWidget::leaveEventHook(QEvent *e) {
@ -2107,7 +2111,7 @@ void InnerWidget::selectSkip(int32 direction) {
return; return;
} }
} else if (!_selected) { } else if (!_selected) {
if (_importantSwitch) { if (importantSwitchShown()) {
_importantSwitchSelected = true; _importantSwitchSelected = true;
} else if (!shownDialogs()->empty() && direction > 0) { } else if (!shownDialogs()->empty() && direction > 0) {
_selected = *shownDialogs()->cbegin(); _selected = *shownDialogs()->cbegin();
@ -2123,7 +2127,7 @@ void InnerWidget::selectSkip(int32 direction) {
auto prev = shownDialogs()->cfind(_selected); auto prev = shownDialogs()->cfind(_selected);
if (prev != shownDialogs()->cbegin()) { if (prev != shownDialogs()->cbegin()) {
_selected = *(--prev); _selected = *(--prev);
} else if (_importantSwitch) { } else if (importantSwitchShown()) {
_importantSwitchSelected = true; _importantSwitchSelected = true;
_selected = nullptr; _selected = nullptr;
} }
@ -2230,7 +2234,7 @@ void InnerWidget::selectSkipPage(int32 pixels, int32 direction) {
for (auto i = shownDialogs()->cfind(_selected), b = shownDialogs()->cbegin(); i != b && (toSkip--);) { for (auto i = shownDialogs()->cfind(_selected), b = shownDialogs()->cbegin(); i != b && (toSkip--);) {
_selected = *(--i); _selected = *(--i);
} }
if (toSkip && _importantSwitch) { if (toSkip && importantSwitchShown()) {
_importantSwitchSelected = true; _importantSwitchSelected = true;
_selected = nullptr; _selected = nullptr;
} }
@ -2302,17 +2306,17 @@ void InnerWidget::loadPeerPhotos() {
bool InnerWidget::switchImportantChats() { bool InnerWidget::switchImportantChats() {
if (!_importantSwitchSelected if (!_importantSwitchSelected
|| !_importantSwitch || !importantSwitchShown()
|| (_state != WidgetState::Default)) { || (_state != WidgetState::Default)) {
return false; return false;
} }
clearSelection(); clearSelection();
if (Global::DialogsMode() == Mode::All) { if (Global::DialogsMode() == Mode::All) {
Global::SetDialogsMode(Mode::Important); Global::SetDialogsMode(Mode::Important);
} } else {
else {
Global::SetDialogsMode(Mode::All); Global::SetDialogsMode(Mode::All);
} }
_mode = Global::DialogsMode();
Local::writeUserSettings(); Local::writeUserSettings();
refresh(); refresh();
_importantSwitchSelected = true; _importantSwitchSelected = true;

View File

@ -227,6 +227,7 @@ private:
UpdateRowSections sections = UpdateRowSection::All); UpdateRowSections sections = UpdateRowSection::All);
void fillSupportSearchMenu(not_null<Ui::PopupMenu*> menu); void fillSupportSearchMenu(not_null<Ui::PopupMenu*> menu);
bool importantSwitchShown() const;
int dialogsOffset() const; int dialogsOffset() const;
int proxyPromotedCount() const; int proxyPromotedCount() const;
int pinnedOffset() const; int pinnedOffset() const;
@ -283,6 +284,7 @@ private:
not_null<Window::Controller*> _controller; not_null<Window::Controller*> _controller;
Mode _mode = Mode();
bool _mouseSelection = false; bool _mouseSelection = false;
std::optional<QPoint> _lastMousePosition; std::optional<QPoint> _lastMousePosition;
Qt::MouseButton _pressButton = Qt::LeftButton; Qt::MouseButton _pressButton = Qt::LeftButton;