Qt: Adjust memory selection by shift-clicking

This commit is contained in:
Jeffrey Pfau 2015-07-04 00:38:08 -07:00
parent abdf448f81
commit e0a6af087e
1 changed files with 14 additions and 6 deletions

View File

@ -316,13 +316,21 @@ void MemoryModel::mousePressEvent(QMouseEvent* event) {
}
QPoint position(event->pos() - QPoint(m_margins.left(), m_margins.top()));
uint32_t address =
int(position.x() / m_cellSize.width()) + (int(position.y() / m_cellSize.height()) + m_top) * 16 + m_base;
uint32_t address = int(position.x() / m_cellSize.width()) +
(int(position.y() / m_cellSize.height()) + m_top) * 16 + m_base;
if (event->button() == Qt::RightButton && isInSelection(address)) {
return;
}
m_selectionAnchor = address & ~(m_align - 1);
m_selection = qMakePair(m_selectionAnchor, m_selectionAnchor + m_align);
if (event->modifiers() & Qt::ShiftModifier) {
if ((address & ~(m_align - 1)) < m_selectionAnchor) {
m_selection = qMakePair(address & ~(m_align - 1), m_selectionAnchor + m_align);
} else {
m_selection = qMakePair(m_selectionAnchor, (address & ~(m_align - 1)) + m_align);
}
} else {
m_selectionAnchor = address & ~(m_align - 1);
m_selection = qMakePair(m_selectionAnchor, m_selectionAnchor + m_align);
}
m_buffer = 0;
m_bufferedNybbles = 0;
emit selectionChanged(m_selection.first, m_selection.second);
@ -336,8 +344,8 @@ void MemoryModel::mouseMoveEvent(QMouseEvent* event) {
}
QPoint position(event->pos() - QPoint(m_margins.left(), m_margins.top()));
uint32_t address =
int(position.x() / m_cellSize.width()) + (int(position.y() / m_cellSize.height()) + m_top) * 16 + m_base;
uint32_t address = int(position.x() / m_cellSize.width()) +
(int(position.y() / m_cellSize.height()) + m_top) * 16 + m_base;
if ((address & ~(m_align - 1)) < m_selectionAnchor) {
m_selection = qMakePair(address & ~(m_align - 1), m_selectionAnchor + m_align);
} else {