Qt/Debugger: Improve scrolling

Reduces the scrolling speed for both keyboard and mouse scrolling so
users are able to navigate the code and memory view line by line
This commit is contained in:
spycrab 2018-08-19 13:29:52 +02:00
parent 12a5fd80bd
commit 5b992f138b
2 changed files with 24 additions and 8 deletions

View File

@ -29,6 +29,10 @@
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
// "Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of
// 120; i.e., 120 units * 1/8 = 15 degrees." (http://doc.qt.io/qt-5/qwheelevent.html#angleDelta)
constexpr double SCROLL_FRACTION_DEGREES = 15.;
constexpr size_t VALID_BRANCH_LENGTH = 10; constexpr size_t VALID_BRANCH_LENGTH = 10;
CodeViewWidget::CodeViewWidget() CodeViewWidget::CodeViewWidget()
@ -484,11 +488,11 @@ void CodeViewWidget::keyPressEvent(QKeyEvent* event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Up: case Qt::Key_Up:
m_address -= 3 * sizeof(u32); m_address -= sizeof(u32);
Update(); Update();
return; return;
case Qt::Key_Down: case Qt::Key_Down:
m_address += 3 * sizeof(u32); m_address += sizeof(u32);
Update(); Update();
return; return;
case Qt::Key_PageUp: case Qt::Key_PageUp:
@ -507,9 +511,13 @@ void CodeViewWidget::keyPressEvent(QKeyEvent* event)
void CodeViewWidget::wheelEvent(QWheelEvent* event) void CodeViewWidget::wheelEvent(QWheelEvent* event)
{ {
int delta = event->delta() > 0 ? -1 : 1; auto delta =
-static_cast<int>(std::round((event->angleDelta().y() / (SCROLL_FRACTION_DEGREES * 8))));
m_address += delta * 3 * sizeof(u32); if (delta == 0)
return;
m_address += delta * sizeof(u32);
Update(); Update();
} }

View File

@ -22,6 +22,10 @@
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
// "Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of
// 120; i.e., 120 units * 1/8 = 15 degrees." (http://doc.qt.io/qt-5/qwheelevent.html#angleDelta)
constexpr double SCROLL_FRACTION_DEGREES = 15.;
MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QTableWidget(parent) MemoryViewWidget::MemoryViewWidget(QWidget* parent) : QTableWidget(parent)
{ {
horizontalHeader()->hide(); horizontalHeader()->hide();
@ -236,11 +240,11 @@ void MemoryViewWidget::keyPressEvent(QKeyEvent* event)
switch (event->key()) switch (event->key())
{ {
case Qt::Key_Up: case Qt::Key_Up:
m_address -= 3 * 16; m_address -= 16;
Update(); Update();
return; return;
case Qt::Key_Down: case Qt::Key_Down:
m_address += 3 * 16; m_address += 16;
Update(); Update();
return; return;
case Qt::Key_PageUp: case Qt::Key_PageUp:
@ -297,9 +301,13 @@ void MemoryViewWidget::ToggleBreakpoint()
void MemoryViewWidget::wheelEvent(QWheelEvent* event) void MemoryViewWidget::wheelEvent(QWheelEvent* event)
{ {
int delta = event->delta() > 0 ? -1 : 1; auto delta =
-static_cast<int>(std::round((event->angleDelta().y() / (SCROLL_FRACTION_DEGREES * 8))));
m_address += delta * 3 * 16; if (delta == 0)
return;
m_address += delta * 16;
Update(); Update();
} }