Pan Function Editor with Hand Shortcut

This commit is contained in:
manongjohn 2021-02-14 00:53:11 -05:00
parent e6c01a7c4b
commit 07624006eb
4 changed files with 69 additions and 29 deletions

View file

@ -76,7 +76,7 @@ private:
QPoint m_startPos, m_oldPos; // mouse click position, last mouse click/drag
// position (window coords)
bool m_isFloating = true;
bool m_spacePressed = false;
bool m_panningArmed = false;
struct Gadget {
Handle m_handle;
int m_kIndex;
@ -213,6 +213,7 @@ protected:
void drawCurrentCurve(QPainter &);
void drawGroupKeyframes(QPainter &);
bool event(QEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
@ -222,7 +223,6 @@ protected:
void openContextMenu(QMouseEvent *e);
void keyPressEvent(QKeyEvent *e) override;
void keyReleaseEvent(QKeyEvent *e) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;

View file

@ -470,11 +470,11 @@ public:
void ensureVisibleCol(int col);
protected:
bool event(QEvent *e) override;
void showEvent(QShowEvent *) override;
void hideEvent(QHideEvent *) override;
void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void timerEvent(QTimerEvent *) override;
void enterEvent(QEvent *) override;

View file

@ -22,6 +22,8 @@
// TnzCore includes
#include "tcommon.h"
#include "tools/toolcommandids.h"
// Qt includes
#include <QPainter>
#include <QPainterPath>
@ -1187,7 +1189,7 @@ void FunctionPanel::mousePressEvent(QMouseEvent *e) {
m_dragTool = 0;
if (e->button() == Qt::MidButton ||
(e->button() == Qt::LeftButton && m_spacePressed)) {
(e->button() == Qt::LeftButton && m_panningArmed)) {
// mid mouse click => panning
bool xLocked = e->pos().x() <= m_valueAxisX;
bool yLocked = e->pos().y() <= m_valueAxisX;
@ -1425,26 +1427,14 @@ void FunctionPanel::mouseDoubleClickEvent(QMouseEvent *) { fitGraphToWindow(); }
//-----------------------------------------------------------------------------
void FunctionPanel::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key::Key_Space) {
m_spacePressed = true;
e->accept();
return;
}
FunctionPanelZoomer(this).exec(e);
}
//-----------------------------------------------------------------------------
void FunctionPanel::keyReleaseEvent(QKeyEvent *e) {
if (e->key() == Qt::Key::Key_Space && !e->isAutoRepeat())
m_spacePressed = false;
// accept intentionally not called here.
}
//-----------------------------------------------------------------------------
void FunctionPanel::enterEvent(QEvent *) {
m_cursor.visible = true;
m_panningArmed = false;
update();
}
@ -1452,7 +1442,7 @@ void FunctionPanel::enterEvent(QEvent *) {
void FunctionPanel::leaveEvent(QEvent *) {
m_cursor.visible = false;
m_spacePressed = false;
m_panningArmed = false;
update();
}
@ -1800,3 +1790,32 @@ QColor FunctionPanel::getChannelColor(QString name, bool active) {
if (!active) color.setAlpha(180);
return color;
}
//-----------------------------------------------------------------------------
bool FunctionPanel::event(QEvent *e) {
if (e->type() != QEvent::KeyPress && e->type() != QEvent::ShortcutOverride &&
e->type() != QEvent::KeyRelease)
return QDialog::event(e);
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
std::string keyStr = QKeySequence(keyEvent->key() + keyEvent->modifiers())
.toString()
.toStdString();
QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
std::string actionId = CommandManager::instance()->getIdFromAction(action);
if (actionId != T_Hand) return QDialog::event(e);
if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) {
m_panningArmed = true;
e->accept();
return true;
} else if (e->type() == QEvent::KeyRelease) {
if (!keyEvent->isAutoRepeat()) m_panningArmed = false;
e->accept();
return true;
}
return QDialog::event(e);
}

View file

@ -7,6 +7,9 @@
#include "toonz/tframehandle.h"
#include "orientation.h"
#include "toonzqt/menubarcommand.h"
#include "tools/toolcommandids.h"
#include <QKeyEvent>
#include <QWheelEvent>
#include <QLabel>
@ -833,10 +836,6 @@ m_dragTool->onDrag(&mouseEvent);
void SpreadsheetViewer::keyPressEvent(QKeyEvent *e) {
int frameCount = m_rowCount;
int row = m_frameHandle->getFrame();
if (e->key() == Qt::Key_Space) {
m_panningArmed = true;
return;
}
if (e->key() == Qt::Key_Up &&
row > 0) { // Row = frame precedente a quello settato
m_frameHandle->setFrame(row - 1);
@ -888,13 +887,6 @@ void SpreadsheetViewer::keyPressEvent(QKeyEvent *e) {
//-----------------------------------------------------------------------------
void SpreadsheetViewer::keyReleaseEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Space && !event->isAutoRepeat())
m_panningArmed = false;
}
//-----------------------------------------------------------------------------
void SpreadsheetViewer::enterEvent(QEvent *) { m_panningArmed = false; }
//-----------------------------------------------------------------------------
@ -953,3 +945,32 @@ void SpreadsheetViewer::ensureVisibleCol(int col) {
int vertValue = m_cellScrollArea->verticalScrollBar()->value();
m_cellScrollArea->ensureVisible(x, vertValue, m_columnWidth / 2, 0);
}
//-----------------------------------------------------------------------------
bool SpreadsheetViewer::event(QEvent *e) {
if (e->type() != QEvent::KeyPress && e->type() != QEvent::ShortcutOverride &&
e->type() != QEvent::KeyRelease)
return QDialog::event(e);
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
std::string keyStr = QKeySequence(keyEvent->key() + keyEvent->modifiers())
.toString()
.toStdString();
QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
std::string actionId = CommandManager::instance()->getIdFromAction(action);
if (actionId != T_Hand) return QDialog::event(e);
if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) {
m_panningArmed = true;
e->accept();
return true;
} else if (e->type() == QEvent::KeyRelease) {
if (!keyEvent->isAutoRepeat()) m_panningArmed = false;
e->accept();
return true;
}
return QDialog::event(e);
}