Merge pull request #212 from smunaut/gui_shift_move

gui: Allow shift+drag to move around the view
This commit is contained in:
Serge Bazanski 2019-02-28 15:26:48 +01:00 committed by GitHub
commit 9aadfef8c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -644,12 +644,16 @@ void FPGAViewWidget::mousePressEvent(QMouseEvent *event)
if (io.WantCaptureMouse)
return;
if (event->buttons() & Qt::RightButton || event->buttons() & Qt::MidButton) {
bool shift = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
bool ctrl = QApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
bool btn_right = event->buttons() & Qt::RightButton;
bool btn_mid = event->buttons() & Qt::MidButton;
bool btn_left = event->buttons() & Qt::LeftButton;
if (btn_right || btn_mid || (btn_left && shift)) {
lastDragPos_ = event->pos();
}
if (event->buttons() & Qt::LeftButton) {
bool ctrl = QApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
if (btn_left && !shift) {
auto world = mouseToWorldCoordinates(event->x(), event->y());
auto closestOr = pickElement(world.x(), world.y());
if (!closestOr) {
@ -681,7 +685,12 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event)
if (io.WantCaptureMouse)
return;
if (event->buttons() & Qt::RightButton || event->buttons() & Qt::MidButton) {
bool shift = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
bool btn_right = event->buttons() & Qt::RightButton;
bool btn_mid = event->buttons() & Qt::MidButton;
bool btn_left = event->buttons() & Qt::LeftButton;
if (btn_right || btn_mid || (btn_left && shift)) {
const int dx = event->x() - lastDragPos_.x();
const int dy = event->y() - lastDragPos_.y();
lastDragPos_ = event->pos();