LiteHtmlHelpViewer: Handle mouse back/forward buttons

Fixes: QTCREATORBUG-25168
Change-Id: I856743040e81a0164e666f14ea7efd10f208f865
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-06-13 11:01:16 +02:00
parent f974488128
commit a1bb539c50

View File

@@ -205,11 +205,14 @@ void LiteHtmlHelpViewer::backward()
{
goBackward(1);
}
void LiteHtmlHelpViewer::goForward(int count)
{
const int steps = qMin(count, int(m_forwardItems.size()));
if (steps == 0)
return;
HistoryItem nextItem = currentHistoryItem();
for (int i = 0; i < count; ++i) {
QTC_ASSERT(!m_forwardItems.empty(), return );
for (int i = 0; i < steps; ++i) {
m_backItems.push_back(nextItem);
nextItem = m_forwardItems.front();
m_forwardItems.erase(m_forwardItems.begin());
@@ -221,9 +224,11 @@ void LiteHtmlHelpViewer::goForward(int count)
void LiteHtmlHelpViewer::goBackward(int count)
{
const int steps = qMin(count, int(m_backItems.size()));
if (steps == 0)
return;
HistoryItem previousItem = currentHistoryItem();
for (int i = 0; i < count; ++i) {
QTC_ASSERT(!m_backItems.empty(), return );
for (int i = 0; i < steps; ++i) {
m_forwardItems.insert(m_forwardItems.begin(), previousItem);
previousItem = m_backItems.back();
m_backItems.pop_back();
@@ -247,6 +252,15 @@ bool LiteHtmlHelpViewer::eventFilter(QObject *src, QEvent *e)
e->ignore();
return true;
}
} else if (e->type() == QEvent::MouseButtonPress) {
auto me = static_cast<QMouseEvent *>(e);
if (me->button() == Qt::BackButton) {
goBackward(1);
return true;
} else if (me->button() == Qt::ForwardButton) {
goForward(1);
return true;
}
}
return HelpViewer::eventFilter(src, e);
}