remember scroll position when reloading msg

This commit is contained in:
Martin Rotter 2020-09-23 13:29:03 +02:00
parent 9f2983d49c
commit 27c0f42899
8 changed files with 53 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -192,3 +192,11 @@ void MessageBrowser::loadMessage(const Message& message, RootItem* root) {
m_txtBrowser->verticalScrollBar()->triggerAction(QScrollBar::SliderToMinimum);
m_searchWidget->hide();
}
double MessageBrowser::verticalScrollBarPosition() const {
return m_txtBrowser->verticalScrollBar()->value();
}
void MessageBrowser::setVerticalScrollBarPosition(double pos) {
m_txtBrowser->verticalScrollBar()->setValue(pos);
}

View File

@ -22,7 +22,10 @@ class MessageBrowser : public QWidget {
public:
explicit MessageBrowser(QWidget* parent = nullptr);
double verticalScrollBarPosition() const;
public slots:
void setVerticalScrollBarPosition(double pos);
void clear();
void reloadFontSettings();
void loadMessage(const Message& message, RootItem* root);

View File

@ -12,6 +12,7 @@
#if defined (USE_WEBENGINE)
#include "gui/webbrowser.h"
#include "gui/webviewer.h"
#else
#include "gui/messagebrowser.h"
#endif
@ -41,7 +42,7 @@ void MessagePreviewer::createConnections() {
}
MessagePreviewer::MessagePreviewer(QWidget* parent)
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)) {
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)), m_verticalScrollBarPosition(0.0) {
#if defined (USE_WEBENGINE)
m_txtMessage = new WebBrowser(this);
#else
@ -75,6 +76,10 @@ WebBrowser* MessagePreviewer::webBrowser() const {
void MessagePreviewer::clear() {
m_txtMessage->clear();
hide();
m_verticalScrollBarPosition = 0.0;
m_root.clear();
m_message = Message();
}
void MessagePreviewer::hideToolbar() {
@ -82,6 +87,10 @@ void MessagePreviewer::hideToolbar() {
}
void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
m_verticalScrollBarPosition = m_txtMessage->verticalScrollBarPosition();
bool same_message = message.m_id == m_message.m_id && m_root == root;
m_message = message;
m_root = root;
@ -90,6 +99,10 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
show();
m_actionSwitchImportance->setChecked(m_message.m_isImportant);
m_txtMessage->loadMessage(message, root);
if (same_message) {
m_txtMessage->setVerticalScrollBarPosition(m_verticalScrollBarPosition);
}
}
}

View File

@ -61,6 +61,7 @@ class MessagePreviewer : public QWidget {
MessageBrowser* m_txtMessage;
#endif
double m_verticalScrollBarPosition;
Message m_message;
QPointer<RootItem> m_root;
QAction* m_actionMarkRead;

View File

@ -77,6 +77,7 @@ class MessagesView : public QTreeView {
// Notify others about message selections.
void currentMessageChanged(const Message& message, RootItem* root);
void currentMessageRemoved();
void willReselectSameMessage();
private:
void sort(int column, Qt::SortOrder order, bool repopulate_data, bool change_header, bool emit_changed_from_header);

View File

@ -88,13 +88,33 @@ WebBrowser::~WebBrowser() {
delete m_layout;
}
double WebBrowser::verticalScrollBarPosition() const {
double position;
QEventLoop loop;
viewer()->page()->runJavaScript(QSL("window.pageYOffset;"), [&position, &loop](const QVariant& val) {
position = val.toDouble();
loop.exit();
});
loop.exec();
return position;
}
void WebBrowser::setVerticalScrollBarPosition(double pos) {
viewer()->page()->runJavaScript(QSL("window.scrollTo(0, %1);").arg(pos));
}
void WebBrowser::reloadFontSettings() {
QFont fon;
fon.fromString(qApp->settings()->value(GROUP(Messages),
SETTING(Messages::PreviewerFontStandard)).toString());
QWebEngineSettings::globalSettings()->setFontFamily(QWebEngineSettings::StandardFont, fon.family());
QWebEngineSettings::globalSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize());
QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::StandardFont, fon.family());
QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::SerifFont, fon.family());
QWebEngineSettings::defaultSettings()->setFontFamily(QWebEngineSettings::SansSerifFont, fon.family());
QWebEngineSettings::defaultSettings()->setFontSize(QWebEngineSettings::DefaultFontSize, fon.pointSize());
}
void WebBrowser::increaseZoom() {

View File

@ -34,7 +34,10 @@ class WebBrowser : public TabContent {
WebBrowser* webBrowser() const;
WebViewer* viewer() const;
double verticalScrollBarPosition() const;
public slots:
void setVerticalScrollBarPosition(double pos);
void reloadFontSettings();
void increaseZoom();