Merge pull request #593 from manongjohn/alter_renameCell_keypress_behavior
Change shortcut usage and navigation while renaming cell
This commit is contained in:
commit
eb141c674e
2 changed files with 79 additions and 19 deletions
|
@ -74,6 +74,7 @@
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -556,7 +557,11 @@ namespace XsheetGUI {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
RenameCellField::RenameCellField(QWidget *parent, XsheetViewer *viewer)
|
RenameCellField::RenameCellField(QWidget *parent, XsheetViewer *viewer)
|
||||||
: QLineEdit(parent), m_viewer(viewer), m_row(-1), m_col(-1) {
|
: QLineEdit(parent)
|
||||||
|
, m_viewer(viewer)
|
||||||
|
, m_row(-1)
|
||||||
|
, m_col(-1)
|
||||||
|
, m_isRenamingCell(false) {
|
||||||
connect(this, SIGNAL(returnPressed()), SLOT(onReturnPressed()));
|
connect(this, SIGNAL(returnPressed()), SLOT(onReturnPressed()));
|
||||||
setContextMenuPolicy(Qt::PreventContextMenu);
|
setContextMenuPolicy(Qt::PreventContextMenu);
|
||||||
setObjectName("RenameCellField");
|
setObjectName("RenameCellField");
|
||||||
|
@ -882,24 +887,39 @@ void RenameCellField::renameCell() {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void RenameCellField::onReturnPressed() {
|
void RenameCellField::moveCellSelection(int direction) {
|
||||||
renameCell();
|
|
||||||
|
|
||||||
// move the cell selection
|
// move the cell selection
|
||||||
TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(
|
TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(
|
||||||
TApp::instance()->getCurrentSelection()->getSelection());
|
TApp::instance()->getCurrentSelection()->getSelection());
|
||||||
if (!cellSelection) return;
|
if (!cellSelection) return;
|
||||||
TCellSelection::Range range = cellSelection->getSelectedCells();
|
TCellSelection::Range range = cellSelection->getSelectedCells();
|
||||||
int offset = range.m_r1 - range.m_r0 + 1;
|
int offset = range.m_r1 - range.m_r0 + direction;
|
||||||
|
if ((m_row + offset) < 0) return;
|
||||||
cellSelection->selectCells(range.m_r0 + offset, range.m_c0,
|
cellSelection->selectCells(range.m_r0 + offset, range.m_c0,
|
||||||
range.m_r1 + offset, range.m_c1);
|
range.m_r1 + offset, range.m_c1);
|
||||||
showInRowCol(m_row + offset, m_col, range.getColCount() > 1);
|
showInRowCol(m_row + offset, m_col, range.getColCount() > 1);
|
||||||
m_viewer->updateCells();
|
m_viewer->updateCells();
|
||||||
|
m_viewer->setCurrentRow(m_row);
|
||||||
TApp::instance()->getCurrentSelection()->notifySelectionChanged();
|
TApp::instance()->getCurrentSelection()->notifySelectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void RenameCellField::onReturnPressed() {
|
||||||
|
renameCell();
|
||||||
|
moveCellSelection(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void RenameCellField::onTabPressed() { moveCellSelection(1); }
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void RenameCellField::onBacktabPressed() { moveCellSelection(-1); }
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void RenameCellField::focusOutEvent(QFocusEvent *e) {
|
void RenameCellField::focusOutEvent(QFocusEvent *e) {
|
||||||
hide();
|
hide();
|
||||||
|
|
||||||
|
@ -910,9 +930,34 @@ void RenameCellField::focusOutEvent(QFocusEvent *e) {
|
||||||
// Override shortcut keys for cell selection commands
|
// Override shortcut keys for cell selection commands
|
||||||
|
|
||||||
bool RenameCellField::eventFilter(QObject *obj, QEvent *e) {
|
bool RenameCellField::eventFilter(QObject *obj, QEvent *e) {
|
||||||
|
if (e->type() == QEvent::KeyPress) {
|
||||||
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
|
||||||
|
int key = keyEvent->key();
|
||||||
|
switch (key) {
|
||||||
|
case Qt::Key_Tab:
|
||||||
|
onTabPressed();
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case Qt::Key_Backtab:
|
||||||
|
onBacktabPressed();
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (e->type() != QEvent::ShortcutOverride)
|
if (e->type() != QEvent::ShortcutOverride)
|
||||||
return QLineEdit::eventFilter(obj, e); // return false;
|
return QLineEdit::eventFilter(obj, e); // return false;
|
||||||
|
|
||||||
|
// If we aren't allowing any shortcuts while renaming, use default editing
|
||||||
|
// commands.
|
||||||
|
if (!Preferences::instance()->isShortcutCommandsWhileRenamingCellEnabled())
|
||||||
|
return QLineEdit::eventFilter(obj, e);
|
||||||
|
|
||||||
|
// No shortcuts in Note Levels
|
||||||
|
TXshColumn *col = m_viewer->getXsheet()->getColumn(m_col);
|
||||||
|
bool noShortcuts = (col && col->getSoundTextColumn()) ? true : false;
|
||||||
|
if (noShortcuts) return QLineEdit::eventFilter(obj, e);
|
||||||
|
|
||||||
TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(
|
TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(
|
||||||
TApp::instance()->getCurrentSelection()->getSelection());
|
TApp::instance()->getCurrentSelection()->getSelection());
|
||||||
if (!cellSelection) return QLineEdit::eventFilter(obj, e);
|
if (!cellSelection) return QLineEdit::eventFilter(obj, e);
|
||||||
|
@ -923,19 +968,13 @@ bool RenameCellField::eventFilter(QObject *obj, QEvent *e) {
|
||||||
QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
|
QAction *action = CommandManager::instance()->getActionFromShortcut(keyStr);
|
||||||
if (!action) return QLineEdit::eventFilter(obj, e);
|
if (!action) return QLineEdit::eventFilter(obj, e);
|
||||||
|
|
||||||
std::string actionId = CommandManager::instance()->getIdFromAction(action);
|
|
||||||
|
|
||||||
// These are usally standard ctrl/command strokes for text editing.
|
// These are usally standard ctrl/command strokes for text editing.
|
||||||
// Default to standard behavior and don't execute OT's action while renaming
|
// Default to standard behavior and don't execute OT's action while renaming
|
||||||
// cell if users prefer to do so.
|
// cell if users prefer to do so.
|
||||||
// Or, always invoke OT's commands when renaming cell even the standard
|
std::string actionId = CommandManager::instance()->getIdFromAction(action);
|
||||||
// command strokes for text editing.
|
if (actionId == "MI_Undo" || actionId == "MI_Redo" ||
|
||||||
// The latter option is demanded by Japanese animation industry in order to
|
|
||||||
// gain efficiency for inputting xsheet.
|
|
||||||
if (!Preferences::instance()->isShortcutCommandsWhileRenamingCellEnabled() &&
|
|
||||||
(actionId == "MI_Undo" || actionId == "MI_Redo" ||
|
|
||||||
actionId == "MI_Clear" || actionId == "MI_Copy" ||
|
actionId == "MI_Clear" || actionId == "MI_Copy" ||
|
||||||
actionId == "MI_Paste" || actionId == "MI_Cut"))
|
actionId == "MI_Paste" || actionId == "MI_Cut")
|
||||||
return QLineEdit::eventFilter(obj, e);
|
return QLineEdit::eventFilter(obj, e);
|
||||||
|
|
||||||
return TCellSelection::isEnabledCommand(actionId);
|
return TCellSelection::isEnabledCommand(actionId);
|
||||||
|
@ -946,6 +985,7 @@ bool RenameCellField::eventFilter(QObject *obj, QEvent *e) {
|
||||||
void RenameCellField::keyPressEvent(QKeyEvent *event) {
|
void RenameCellField::keyPressEvent(QKeyEvent *event) {
|
||||||
if (event->key() == Qt::Key_Escape) {
|
if (event->key() == Qt::Key_Escape) {
|
||||||
clearFocus();
|
clearFocus();
|
||||||
|
m_viewer->setFocus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +1003,8 @@ void RenameCellField::keyPressEvent(QKeyEvent *event) {
|
||||||
stride.setFrame(cellSelection->getSelectedCells().getRowCount());
|
stride.setFrame(cellSelection->getSelectedCells().getRowCount());
|
||||||
|
|
||||||
CellPosition offset;
|
CellPosition offset;
|
||||||
switch (int key = event->key()) {
|
int key = event->key();
|
||||||
|
switch (key) {
|
||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
case Qt::Key_Down:
|
case Qt::Key_Down:
|
||||||
offset = m_viewer->orientation()->arrowShift(key);
|
offset = m_viewer->orientation()->arrowShift(key);
|
||||||
|
@ -971,11 +1012,17 @@ void RenameCellField::keyPressEvent(QKeyEvent *event) {
|
||||||
case Qt::Key_Left:
|
case Qt::Key_Left:
|
||||||
case Qt::Key_Right:
|
case Qt::Key_Right:
|
||||||
// ctrl+left/right arrow for moving cursor to the end in the field
|
// ctrl+left/right arrow for moving cursor to the end in the field
|
||||||
if (isCtrlPressed &&
|
if (!isCtrlPressed ||
|
||||||
!Preferences::instance()->isUseArrowKeyToShiftCellSelectionEnabled()) {
|
!Preferences::instance()->isUseArrowKeyToShiftCellSelectionEnabled()) {
|
||||||
|
// Allow left/right movement inside field. If you go too far, you will
|
||||||
|
// shift cells
|
||||||
|
int curPos = cursorPosition();
|
||||||
|
if ((key == Qt::Key_Left && curPos > 0) ||
|
||||||
|
(key == Qt::Key_Right && curPos < text().size())) {
|
||||||
QLineEdit::keyPressEvent(event);
|
QLineEdit::keyPressEvent(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
offset = m_viewer->orientation()->arrowShift(key);
|
offset = m_viewer->orientation()->arrowShift(key);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1017,6 +1064,8 @@ void RenameCellField::showEvent(QShowEvent *) {
|
||||||
bool ret = connect(TApp::instance()->getCurrentXsheet(),
|
bool ret = connect(TApp::instance()->getCurrentXsheet(),
|
||||||
SIGNAL(xsheetChanged()), this, SLOT(onXsheetChanged()));
|
SIGNAL(xsheetChanged()), this, SLOT(onXsheetChanged()));
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
|
m_isRenamingCell = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -1024,6 +1073,7 @@ void RenameCellField::showEvent(QShowEvent *) {
|
||||||
void RenameCellField::hideEvent(QHideEvent *) {
|
void RenameCellField::hideEvent(QHideEvent *) {
|
||||||
disconnect(TApp::instance()->getCurrentXsheet(), SIGNAL(xsheetChanged()),
|
disconnect(TApp::instance()->getCurrentXsheet(), SIGNAL(xsheetChanged()),
|
||||||
this, SLOT(onXsheetChanged()));
|
this, SLOT(onXsheetChanged()));
|
||||||
|
m_isRenamingCell = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -26,6 +26,7 @@ class RenameCellField final : public QLineEdit {
|
||||||
int m_row;
|
int m_row;
|
||||||
int m_col;
|
int m_col;
|
||||||
XsheetViewer *m_viewer;
|
XsheetViewer *m_viewer;
|
||||||
|
bool m_isRenamingCell;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenameCellField(QWidget *parent, XsheetViewer *viewer);
|
RenameCellField(QWidget *parent, XsheetViewer *viewer);
|
||||||
|
@ -35,6 +36,8 @@ public:
|
||||||
|
|
||||||
bool isLocatedAt(int row, int col) { return row == m_row && col == m_col; }
|
bool isLocatedAt(int row, int col) { return row == m_row && col == m_col; }
|
||||||
|
|
||||||
|
bool isRenamingCell() { return m_isRenamingCell; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void focusOutEvent(QFocusEvent *) override;
|
void focusOutEvent(QFocusEvent *) override;
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
@ -46,6 +49,10 @@ protected:
|
||||||
void renameCell();
|
void renameCell();
|
||||||
void renameSoundTextColumn(TXshSoundTextColumn *sndTextCol, const QString &s);
|
void renameSoundTextColumn(TXshSoundTextColumn *sndTextCol, const QString &s);
|
||||||
|
|
||||||
|
void moveCellSelection(int direction);
|
||||||
|
void onTabPressed();
|
||||||
|
void onBacktabPressed();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onReturnPressed();
|
void onReturnPressed();
|
||||||
void onXsheetChanged();
|
void onXsheetChanged();
|
||||||
|
@ -134,6 +141,9 @@ public:
|
||||||
m_renameCell->showInRowCol(row, col, multiColumnSelected);
|
m_renameCell->showInRowCol(row, col, multiColumnSelected);
|
||||||
}
|
}
|
||||||
void hideRenameField() { m_renameCell->hide(); }
|
void hideRenameField() { m_renameCell->hide(); }
|
||||||
|
bool isRenamingCell() {
|
||||||
|
return m_renameCell && m_renameCell->isRenamingCell();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
|
Loading…
Reference in a new issue