summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-18 20:34:30 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commitd1fffd66170d7548926b205dda7d8de81bef3384 (patch)
tree0a1f5f76d14f95c1174af6dd3a8964dd5f3d6dd8 /src
parentTry to fix CI, no match for QString::arg(QStringRef) (diff)
downloadnheko-d1fffd66170d7548926b205dda7d8de81bef3384.tar.xz
Implement simple scroll state handling
Diffstat (limited to 'src')
-rw-r--r--src/timeline2/TimelineModel.cpp19
-rw-r--r--src/timeline2/TimelineModel.h12
-rw-r--r--src/timeline2/TimelineViewManager.cpp1
3 files changed, 31 insertions, 1 deletions
diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp

index 46a33add..7a2edda4 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp
@@ -625,3 +625,22 @@ TimelineModel::replyAction(QString id) emit ChatPage::instance()->messageReply(related); } + +int +TimelineModel::idToIndex(QString id) const +{ + if (id.isEmpty()) + return -1; + for (int i = 0; i < (int)eventOrder.size(); i++) + if (id == eventOrder[i]) + return i; + return -1; +} + +QString +TimelineModel::indexToId(int index) const +{ + if (index < 0 || index >= (int)eventOrder.size()) + return ""; + return eventOrder[index]; +} diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h
index b2481668..17f83323 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h
@@ -81,6 +81,8 @@ struct DecryptionResult class TimelineModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY( + int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) public: explicit TimelineModel(QString room_id, QObject *parent = 0); @@ -112,6 +114,8 @@ public: Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void replyAction(QString id); + Q_INVOKABLE int idToIndex(QString id) const; + Q_INVOKABLE QString indexToId(int index) const; void addEvents(const mtx::responses::Timeline &events); template<class T> @@ -119,6 +123,12 @@ public: public slots: void fetchHistory(); + void setCurrentIndex(int index) + { + currentId = indexToId(index); + emit currentIndexChanged(index); + } + int currentIndex() const { return idToIndex(currentId); } private slots: // Add old events at the top of the timeline. @@ -129,6 +139,7 @@ signals: void oldMessagesRetrieved(const mtx::responses::Messages &res); void messageFailed(const std::string txn_id); void messageSent(const std::string txn_id, std::string event_id); + void currentIndexChanged(int index); private: DecryptionResult decryptEvent( @@ -146,6 +157,7 @@ private: bool paginationInProgress = false; QHash<QString, QColor> userColors; + QString currentId; }; template<class T> diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp
index 93a42543..8233d33e 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp
@@ -14,7 +14,6 @@ TimelineViewManager::TimelineViewManager(QWidget *parent) 0, "MtxEvent", "Can't instantiate enum!"); - view = new QQuickView(); container = QWidget::createWindowContainer(view, parent); container->setMinimumSize(200, 200);