From 00f0a70454f46031d1bfc5720c03c1a13e062f25 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 9 Feb 2015 23:19:48 +0000 Subject: [PATCH] some fixes in navigation --- Telegram/SourceFiles/dialogswidget.cpp | 16 +++++++++++----- Telegram/SourceFiles/dialogswidget.h | 1 + Telegram/SourceFiles/gui/scrollarea.cpp | 8 ++++++++ Telegram/SourceFiles/gui/scrollarea.h | 1 + Telegram/SourceFiles/historywidget.cpp | 18 +++++++++++++----- Telegram/SourceFiles/mainwidget.cpp | 20 +++++++++++++------- 6 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 16755c3be..33b50dc7a 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -192,9 +192,6 @@ void DialogsListWidget::peopleResultPaint(UserData *user, QPainter &p, int32 w, } void DialogsListWidget::activate() { - if (_state == DefaultState && !sel) { - selectSkip(1); - } } void DialogsListWidget::mouseMoveEvent(QMouseEvent *e) { @@ -728,6 +725,10 @@ DialogsListWidget::State DialogsListWidget::state() const { return _state; } +bool DialogsListWidget::hasFilteredResults() const { + return !filterResults.isEmpty(); +} + void DialogsListWidget::clearFilter() { if (_state == FilteredState || _state == SearchedState) { _state = DefaultState; @@ -1591,8 +1592,13 @@ void DialogsWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape) { e->ignore(); } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { - if (!list.choosePeer() && (list.state() == DialogsListWidget::SearchedState || list.state() == DialogsListWidget::FilteredState)) { - onSearchMessages(); + if (!list.choosePeer()) { + if (list.state() == DialogsListWidget::DefaultState || list.state() == DialogsListWidget::SearchedState || (list.state() == DialogsListWidget::FilteredState && list.hasFilteredResults())) { + list.selectSkip(1); + list.choosePeer(); + } else { + onSearchMessages(); + } } } else if (e->key() == Qt::Key_Down) { list.setMouseSel(false); diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index 055c45839..5d3a96441 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -86,6 +86,7 @@ public: }; void setState(State newState); State state() const; + bool hasFilteredResults() const; void onFilterUpdate(QString newFilter, bool force = false); void itemRemoved(HistoryItem *item); diff --git a/Telegram/SourceFiles/gui/scrollarea.cpp b/Telegram/SourceFiles/gui/scrollarea.cpp index 57ef063e1..1125f4b98 100644 --- a/Telegram/SourceFiles/gui/scrollarea.cpp +++ b/Telegram/SourceFiles/gui/scrollarea.cpp @@ -548,6 +548,14 @@ void ScrollArea::moveEvent(QMoveEvent *e) { emit geometryChanged(); } +void ScrollArea::keyPressEvent(QKeyEvent *e) { + if ((e->key() == Qt::Key_Up || e->key() == Qt::Key_Down) && e->modifiers().testFlag(Qt::AltModifier)) { + e->ignore(); + } else { + QScrollArea::keyPressEvent(e); + } +} + void ScrollArea::enterEvent(QEvent *e) { if (_st.hiding) { hor.hideTimeout(_st.hiding); diff --git a/Telegram/SourceFiles/gui/scrollarea.h b/Telegram/SourceFiles/gui/scrollarea.h index 17057db89..fcd7fd4bf 100644 --- a/Telegram/SourceFiles/gui/scrollarea.h +++ b/Telegram/SourceFiles/gui/scrollarea.h @@ -113,6 +113,7 @@ public: void resizeEvent(QResizeEvent *e); void moveEvent(QMoveEvent *e); + void keyPressEvent(QKeyEvent *e); void enterEvent(QEvent *e); void leaveEvent(QEvent *e); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index c0055639c..3f5fb0f30 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -884,6 +884,8 @@ void HistoryList::keyPressEvent(QKeyEvent *e) { copySelectedText(); } else if (e == QKeySequence::Delete) { historyWidget->onDeleteSelected(); + } else { + e->ignore(); } } @@ -1723,6 +1725,9 @@ void HistoryWidget::typingDone(const MTPBool &result, mtpRequestId req) { } void HistoryWidget::activate() { + if (hist && !_histInited) { + checkUnreadLoaded(); + } if (App::main()->selectingPeer()) { if (hiderOffered) { App::main()->focusPeerSelect(); @@ -3273,7 +3278,10 @@ void HistoryWidget::updateScrollColors() { void HistoryWidget::updateListSize(int32 addToY, bool initial, bool loadedDown, HistoryItem *resizedItem) { if (!hist || (!_histInited && !initial)) return; - if (!App::wnd()->isVisible()) return; // scrollTopMax etc are not working after recountHeight() + if (!isVisible()) { + if (initial) _histInited = false; + return; // scrollTopMax etc are not working after recountHeight() + } int32 newScrollHeight = height() - (hist->readyForWork() && (!histPeer->chat || !histPeer->asChat()->forbidden) ? (_field.height() + 2 * st::sendPadding) : 0); bool wasAtBottom = _scroll.scrollTop() + 1 > _scroll.scrollTopMax(), needResize = _scroll.width() != width() || _scroll.height() != newScrollHeight; @@ -3375,7 +3383,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { App::main()->peerAfter(histPeer, hist ? hist->activeMsgId : 0, after, afterMsgId); if (after) App::main()->showPeer(after->id, afterMsgId); } else { - _scroll.scrollToY(_scroll.scrollTop() + _scroll.height()); + _scroll.keyPressEvent(e); } } else if (e->key() == Qt::Key_PageUp) { if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::MetaModifier)) { @@ -3384,7 +3392,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { App::main()->peerBefore(histPeer, hist ? hist->activeMsgId : 0, before, beforeMsgId); if (before) App::main()->showPeer(before->id, beforeMsgId); } else { - _scroll.scrollToY(_scroll.scrollTop() - _scroll.height()); + _scroll.keyPressEvent(e); } } else if (e->key() == Qt::Key_Down) { if (e->modifiers() & Qt::AltModifier) { @@ -3393,7 +3401,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { App::main()->peerAfter(histPeer, hist ? hist->activeMsgId : 0, after, afterMsgId); if (after) App::main()->showPeer(after->id, afterMsgId); } else if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) { - _scroll.scrollToY(_scroll.scrollTop() + _scroll.height() / 10); + _scroll.keyPressEvent(e); } } else if (e->key() == Qt::Key_Up) { if (e->modifiers() & Qt::AltModifier) { @@ -3402,7 +3410,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { App::main()->peerBefore(histPeer, hist ? hist->activeMsgId : 0, before, beforeMsgId); if (before) App::main()->showPeer(before->id, beforeMsgId); } else if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) { - _scroll.scrollToY(_scroll.scrollTop() - _scroll.height() / 10); + _scroll.keyPressEvent(e); } } else if ((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) && ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::MetaModifier))) { PeerData *p = 0; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 23ae62185..7ddc39003 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -820,6 +820,7 @@ void MainWidget::stopAnimActive() { void MainWidget::searchMessages(const QString &query) { dialogs.searchMessages(query); + if (!cWideMode()) onShowDialogs(); } void MainWidget::preloadOverviews(PeerData *peer) { @@ -1425,7 +1426,7 @@ void MainWidget::showPeer(quint64 peerId, qint32 msgId, bool back, bool force) { hider = 0; } if (force || !selectingPeer()) { - if ((history.isHidden() && (profile || overview)) || !cWideMode()) { + if (!animating() && ((history.isHidden() && (profile || overview)) || (!cWideMode() && (history.isHidden() || !peerId)))) { dialogs.enableShadow(false); if (peerId) { _topBar.enableShadow(false); @@ -1469,9 +1470,11 @@ void MainWidget::showPeer(quint64 peerId, qint32 msgId, bool back, bool force) { if (onlyDialogs) { _topBar.hide(); history.hide(); - dialogs.show(); - if (!animCache.isNull()) { - dialogs.animShow(animCache); + if (!animating()) { + dialogs.show(); + if (!animCache.isNull()) { + dialogs.animShow(animCache); + } } } else { if (noPeer) { @@ -1479,9 +1482,11 @@ void MainWidget::showPeer(quint64 peerId, qint32 msgId, bool back, bool force) { resizeEvent(0); } if (!cWideMode()) dialogs.hide(); - history.show(); - if (!animCache.isNull()) { - history.animShow(animCache, animTopBarCache, back); + if (!animating()) { + history.show(); + if (!animCache.isNull()) { + history.animShow(animCache, animTopBarCache, back); + } } } } @@ -2077,6 +2082,7 @@ void MainWidget::onPeerShown(PeerData *peer) { _topBar.hide(); } resizeEvent(0); + if (animating()) _topBar.hide(); } void MainWidget::onUpdateNotifySettings() {