Commit 652c53bf authored by Daniel Teske's avatar Daniel Teske
Browse files

EnvironmentWidget: Tweak keyboard navigation



Make Enter/Return start editing the widget and also make Tab/Shift+Tab
order while editing saner.

Task-number: QTCREATORBUG-13013
Change-Id: Ie514438f15c5a15920ca3e2bb7ac83548cd0b9c4
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 4da91bef
......@@ -42,6 +42,7 @@
#include <QTreeView>
#include <QTextDocument> // for Qt::escape
#include <QVBoxLayout>
#include <QKeyEvent>
namespace ProjectExplorer {
......@@ -93,7 +94,7 @@ EnvironmentWidget::EnvironmentWidget(QWidget *parent, QWidget *additionalDetails
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setMargin(0);
d->m_environmentView = new QTreeView(this);
d->m_environmentView = new Internal::EnvironmentTreeView(this);
d->m_environmentView->setModel(d->m_model);
d->m_environmentView->setMinimumHeight(400);
d->m_environmentView->setRootIsDecorated(false);
......@@ -295,4 +296,46 @@ void EnvironmentWidget::invalidateCurrentIndex()
environmentCurrentIndexChanged(QModelIndex());
}
Internal::EnvironmentTreeView::EnvironmentTreeView(QWidget *parent)
: QTreeView(parent)
{
}
QModelIndex Internal::EnvironmentTreeView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
{
QModelIndex idx = currentIndex();
int column = idx.column();
int row = idx.row();
if (cursorAction == QAbstractItemView::MoveNext) {
if (column == 0)
return idx.sibling(row, 1);
else if (row + 1 < model()->rowCount())
return idx.sibling(row + 1, 0);
else // On last column in last row
return idx;
} else if (cursorAction == QAbstractItemView::MovePrevious) {
if (column == 1)
return idx.sibling(row, 0);
else if (row - 1 >= 0)
return idx.sibling(row - 1, 1);
else // On first column in first row
return idx;
}
return QTreeView::moveCursor(cursorAction, modifiers);
}
void Internal::EnvironmentTreeView::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
if (!edit(currentIndex(), EditKeyPressed, event))
event->ignore();
return;
}
QTreeView::keyPressEvent(event);
}
} // namespace ProjectExplorer
......@@ -33,6 +33,7 @@
#include "projectexplorer_export.h"
#include <QWidget>
#include <QTreeView>
QT_FORWARD_DECLARE_CLASS(QModelIndex)
......@@ -42,6 +43,17 @@ class EnvironmentItem;
}
namespace ProjectExplorer {
namespace Internal {
class EnvironmentTreeView : public QTreeView
{
public:
EnvironmentTreeView(QWidget *parent);
protected:
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
void keyPressEvent(QKeyEvent *event);
};
}
class EnvironmentWidgetPrivate;
class PROJECTEXPLORER_EXPORT EnvironmentWidget : public QWidget
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment