Skip to content

Commit

Permalink
Merge pull request SINTEF-Geometry#370 from sbriseid/viewlib_touchpad…
Browse files Browse the repository at this point in the history
…_fix

Fixed issue with (Left) Alt button used for menu items, messing up th…
  • Loading branch information
sbriseid authored Sep 26, 2024
2 parents 732d7e2 + 4e5eb6d commit 13327ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 98 deletions.
10 changes: 1 addition & 9 deletions viewlib/include/GoTools/viewlib/gvView.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@ public slots:
/// zoom and rotate the camera.
virtual void mouseMoveEvent(QMouseEvent* e);

/// Overridden.
virtual void keyPressEvent(QKeyEvent* e);
/// Overridden.
virtual void keyReleaseEvent(QKeyEvent* e);

virtual bool get3Dpoint(int mousex, int mousey, Vector3D &objpt);

void drawOverlay();
Expand Down Expand Up @@ -251,13 +246,10 @@ public slots:
gvTexture *coarseTex_;
gvTexture *fineTex_;

QPainter* painter_;
QPainter* painter_;

bool focus_on_origin_;

bool ctrl_pressed_;
bool shift_pressed_;
bool alt_pressed_;
bool trackpad_nav_enabled_;
};

Expand Down
100 changes: 11 additions & 89 deletions viewlib/src/gvView.C
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ gvView::gvView(gvData& data,
fineTex_(0),
painter_(0),
focus_on_origin_(false),
ctrl_pressed_(false),
shift_pressed_(false),
alt_pressed_(false),
trackpad_nav_enabled_(false)
{
data.registerObserver(this);
Expand Down Expand Up @@ -128,9 +125,6 @@ gvView::gvView(const QGLFormat &format, gvData& data,
fineTex_(0),
painter_(0),
focus_on_origin_(false),
ctrl_pressed_(false),
shift_pressed_(false),
alt_pressed_(false),
trackpad_nav_enabled_(false)
{
data.registerObserver(this);
Expand Down Expand Up @@ -831,9 +825,14 @@ void gvView::mouseReleaseEvent(QMouseEvent* e)
void gvView::mouseMoveEvent(QMouseEvent* e)
//===========================================================================
{
bool trackpad_rotate = (alt_pressed_ && !ctrl_pressed_ && !shift_pressed_);
bool trackpad_zoom = (ctrl_pressed_ && shift_pressed_ && !alt_pressed_);
bool trackpad_pan = (shift_pressed_ && !alt_pressed_ && !ctrl_pressed_);
bool alt_pressed = (QApplication::keyboardModifiers() & Qt::AltModifier);
bool ctrl_pressed = (QApplication::keyboardModifiers() & Qt::ControlModifier);
bool shift_pressed = (QApplication::keyboardModifiers() & Qt::ShiftModifier);

bool trackpad_rotate = (alt_pressed && !ctrl_pressed && !shift_pressed);
bool trackpad_zoom = (ctrl_pressed && shift_pressed && !alt_pressed);
bool trackpad_pan = (shift_pressed && !alt_pressed && !ctrl_pressed);

bool trackpad_nav_enabled = (trackpad_rotate || trackpad_zoom || trackpad_pan);
if (!trackpad_nav_enabled_ && trackpad_nav_enabled)
{
Expand Down Expand Up @@ -866,8 +865,8 @@ void gvView::mouseMoveEvent(QMouseEvent* e)
return;
}

// std::cout << "ctrl_pressed: " << ctrl_pressed_ << ", shift_pressed: " << shift_pressed_ <<
// ", alt_pressed: " << alt_pressed_ << std::endl;
// std::cout << "ctrl_pressed: " << ctrl_pressed << ", shift_pressed: " << shift_pressed <<
// ", alt_pressed: " << alt_pressed << std::endl;

// Rotate. Alt is useful for trackpads.
if ((e->buttons() & Qt::LeftButton) || trackpad_rotate)
Expand Down Expand Up @@ -938,7 +937,7 @@ void gvView::mouseMoveEvent(QMouseEvent* e)

// Pan. Shift is useful for trackpads.
if ((e->buttons() & Qt::RightButton) || trackpad_pan)
//((e->buttons() & Qt::LeftButton) && shift_pressed_))
//((e->buttons() & Qt::LeftButton) && shift_pressed))
{
if (e->buttons() & Qt::ShiftModifier)
{
Expand All @@ -964,83 +963,6 @@ void gvView::mouseMoveEvent(QMouseEvent* e)
updateGL();
}


//===========================================================================
void gvView::keyPressEvent(QKeyEvent* e)
//===========================================================================
{

if (e->modifiers().testFlag(Qt::ControlModifier))
{
//std::cout << "Control pressed!" << std::endl;
ctrl_pressed_ = true;
}

//if (Qt::ShiftModifier == QApplication::keyboardModifiers())
if (e->modifiers().testFlag(Qt::ShiftModifier))
{
//std::cout << "Shift pressed!" << std::endl;
shift_pressed_ = true;
}

//if (Qt::AltModifier == QApplication::keyboardModifiers())
if (e->modifiers().testFlag(Qt::AltModifier))
{
//std::cout << "Alt pressed!" << std::endl;
alt_pressed_ = true;
}

// if (keyboard_modifier_ == Qt::NoModifier) {
// if (keyboard_event_ == NULL) {
// // keyboard_modifier_ = e->modifiers();
// keyboard_event_ = e;
// }
// keyboard_is_active_ = true;
// }
}


//===========================================================================
void gvView::keyReleaseEvent(QKeyEvent* e)
//===========================================================================
{
if (trackpad_nav_enabled_)
{
mouse_is_active_ = false;
}

ctrl_pressed_ = false;
shift_pressed_ = false;
alt_pressed_ = false;
trackpad_nav_enabled_ = false;

if (e->key() == Qt::ControlModifier)
{
ctrl_pressed_ = false;
}

if (e->modifiers().testFlag(Qt::ShiftModifier))
{
shift_pressed_ = false;
}

if (e->modifiers().testFlag(Qt::AltModifier))
{
alt_pressed_ = false;
}

// // if (keyboard_modifier_ & e->modifiers()) {
// if (keyboard_event_ != NULL) {
// // keyboard_modifier_ = Qt::NoModifier;
// keyboard_event_ = NULL;
// }
// keyboard_is_active_ = false;
// }

}



//===========================================================================
void gvView::focusOnBox()
//===========================================================================
Expand Down

0 comments on commit 13327ae

Please sign in to comment.