enable Ctrl+J and Ctrl+K navigation in VDirectoryTree

This commit is contained in:
Le Tan 2017-04-04 23:01:10 +08:00
parent 6e0f1d38b4
commit 3ca968169f
2 changed files with 41 additions and 1 deletions

View File

@ -112,6 +112,10 @@ QComboBox#NotebookSelector {
icon-size: 30px;
}
QComboBox#NotebookSelector::focus {
background-color: @focus-color;
}
QComboBox#NotebookSelector::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;

View File

@ -74,6 +74,7 @@ void VDirectoryTree::initActions()
void VDirectoryTree::setNotebook(VNotebook *p_notebook)
{
setFocus();
if (m_notebook == p_notebook) {
return;
}
@ -512,12 +513,47 @@ void VDirectoryTree::mousePressEvent(QMouseEvent *event)
void VDirectoryTree::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return) {
int key = event->key();
int modifiers = event->modifiers();
switch (key) {
case Qt::Key_Return:
{
QTreeWidgetItem *item = currentItem();
if (item) {
item->setExpanded(!item->isExpanded());
}
break;
}
case Qt::Key_J:
{
if (modifiers == Qt::ControlModifier) {
event->accept();
QKeyEvent *downEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down,
Qt::NoModifier);
QCoreApplication::postEvent(this, downEvent);
return;
}
break;
}
case Qt::Key_K:
{
if (modifiers == Qt::ControlModifier) {
event->accept();
QKeyEvent *upEvent = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up,
Qt::NoModifier);
QCoreApplication::postEvent(this, upEvent);
return;
}
break;
}
default:
break;
}
QTreeWidget::keyPressEvent(event);
}