return setLocalValue("DynamicBacklogAmount", amount);
}
+bool BacklogSettings::ensureBacklogOnBufferShow() const
+{
+ // This settings key is also used within BufferWidget::BufferWidget()
+ return localValue("EnsureBacklogOnBufferShow", true).toBool();
+}
+
+void BacklogSettings::setEnsureBacklogOnBufferShow(bool enabled)
+{
+ return setLocalValue("EnsureBacklogOnBufferShow", enabled);
+}
+
int BacklogSettings::fixedBacklogAmount() const
{
return localValue("FixedBacklogAmount", 500).toInt();
int dynamicBacklogAmount() const;
void setDynamicBacklogAmount(int amount);
+ /**
+ * Gets if a buffer should fetch backlog upon show to provide a scrollable amount of backlog
+ *
+ * @return True if showing a buffer without scrollbar visible fetches backlog, otherwise false
+ */
+ bool ensureBacklogOnBufferShow() const;
+ /**
+ * Sets if a buffer should fetch backlog upon show to provide a scrollable amount of backlog
+ *
+ * @param enabled True if showing a buffer without scrollbar fetches backlog, otherwise false
+ */
+ void setEnsureBacklogOnBufferShow(bool enabled);
+
int fixedBacklogAmount() const;
void setFixedBacklogAmount(int amount);
#include "action.h"
#include "actioncollection.h"
+#include "backlogsettings.h"
#include "chatline.h"
#include "chatview.h"
#include "chatviewsearchbar.h"
ChatViewSettings s;
s.initAndNotify("AutoMarkerLine", this, &BufferWidget::setAutoMarkerLine, true);
s.initAndNotify("AutoMarkerLineOnLostFocus", this, &BufferWidget::setAutoMarkerLineOnLostFocus, true);
+
+ BacklogSettings backlogSettings;
+ backlogSettings.initAndNotify("EnsureBacklogOnBufferShow", this, &BufferWidget::setEnsureBacklogOnBufferShow);
}
BufferWidget::~BufferWidget()
_autoMarkerLineOnLostFocus = v.toBool();
}
+void BufferWidget::setEnsureBacklogOnBufferShow(const QVariant& v)
+{
+ _ensureBacklogOnBufferShow = v.toBool();
+}
+
AbstractChatView* BufferWidget::createChatView(BufferId id)
{
ChatView* chatView;
Q_ASSERT(view);
ui.stackedWidget->setCurrentWidget(view);
_chatViewSearchController->setScene(view->scene());
+ if (_ensureBacklogOnBufferShow) {
+ // Try to ensure some messages are visible
+ view->requestBacklogForScroll();
+ }
}
}
void setAutoMarkerLine(const QVariant&);
void setAutoMarkerLineOnLostFocus(const QVariant&);
+ /**
+ * Sets the local cache of whether or not a buffer should fetch backlog upon show to provide a
+ * scrollable amount of backlog
+ *
+ * @seealso BacklogSettings::setEnsureBacklogOnBufferShow()
+ */
+ void setEnsureBacklogOnBufferShow(const QVariant&);
private:
Ui::BufferWidget ui;
bool _autoMarkerLine;
bool _autoMarkerLineOnLostFocus;
+ bool _ensureBacklogOnBufferShow; ///< If a buffer fetches backlog upon show until scrollable
};
case Qt::Key_Down:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
- if (!verticalScrollBar()->isVisible()) {
- scene()->requestBacklog();
+ if (requestBacklogForScroll()) {
return true;
}
default:
if (event->type() == QEvent::Wheel
|| (event->type() == QEvent::TouchBegin && ((QTouchEvent*)event)->device()->type() == QTouchDevice::TouchScreen)
|| event->type() == QEvent::TouchUpdate) {
- if (!verticalScrollBar()->isVisible()) {
- scene()->requestBacklog();
+ if (requestBacklogForScroll()) {
return true;
}
}
_linesWithCache.remove(line);
}
+bool ChatView::requestBacklogForScroll()
+{
+ if (!verticalScrollBar()->isVisible()) {
+ // Not able to scroll, fetch backlog
+ //
+ // Future improvement: continue fetching backlog in chunks until the scrollbar is visible,
+ // or the beginning of the buffer has been reached.
+ scene()->requestBacklog();
+ // Backlog has been requested
+ return true;
+ }
+ else {
+ // Scrollbar already visible, no backlog requested
+ return false;
+ }
+}
+
void ChatView::checkChatLineCaches()
{
qreal top = mapToScene(viewport()->rect().topLeft()).y() - 10; // some grace area to avoid premature cleaning
*/
void setHasCache(ChatLine* line, bool hasCache = true);
+ /**
+ * Requests backlog if the scrollbar is not currently visible
+ *
+ * Use this whenever trying to scroll the backlog to try to ensure some text is visible. If the
+ * backlog does not have additional messages or those messages are filtered out, the scrollbar
+ * might remain invisible.
+ *
+ * @return True if the scrollbar isn't visible and a backlog request was made, otherwise false
+ */
+ bool requestBacklogForScroll();
+
public slots:
inline virtual void clear() {}
void zoomIn();
<x>0</x>
<y>0</y>
<width>446</width>
- <height>325</height>
+ <height>329</height>
</rect>
</property>
<property name="windowTitle">
</item>
</layout>
</item>
+ <item>
+ <widget class="QCheckBox" name="ensureBacklogOnBufferShow">
+ <property name="toolTip">
+ <string>When switching to a chat, more backlog will be fetched if no messages are shown yet or the scrollbar isn't visible. Useful when not fetching any initial backlog.</string>
+ </property>
+ <property name="text">
+ <string>Fetch backlog if needed when switching chats</string>
+ </property>
+ <property name="settingsKey" stdset="0">
+ <string notr="true">EnsureBacklogOnBufferShow</string>
+ </property>
+ <property name="defaultValue" stdset="0">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
<item>
<widget class="Line" name="line">
<property name="orientation">