From 41e54bc5bded308687ad090afef9e5737edbe9b3 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 6 Jun 2015 10:47:15 +0200 Subject: Navigate NewPicsDialog by keyboard MappingView: * Key_Right: add mapping * Ctrl-Key_Right: shift focus to ResultView * Delete: clear all mappings ResultView: * Key_Left: remove mapping * Ctrl-Key_Left: shift focus to MappingView --- mappingtreewidget.cpp | 71 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 22 deletions(-) (limited to 'mappingtreewidget.cpp') diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index ab9b844..dcebb02 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -208,15 +208,6 @@ void MappingTreeWidget::deleteType(){ } } -void MappingTreeWidget::selectPath(const QList &data, bool reverse){ - QModelIndex pathIdx = mModel->indexFromParentPath(data, reverse); - if(!pathIdx.isValid()){ - return; - } - QModelIndex real = mProxy->mapFromSource(pathIdx); - mTree->setCurrentIndex(real); -} - void MappingTreeWidget::hideEvent(QHideEvent *event){ QString type = mTypeBox->currentText(); if(!type.isEmpty()){ @@ -283,11 +274,38 @@ void MappingTreeView::contextMenuEvent(QContextMenuEvent *e){ ctxMenu.exec(e->globalPos()); } +void MappingTreeView::keyPressEvent(QKeyEvent *e){ + if(e->key() == Qt::Key_Right && (e->modifiers() & Qt::ControlModifier)){ + clearFocus(); + emit shiftFocus(); + return; + } + if(e->key() == Qt::Key_Right){ + emit addMapping(); + } + if(e->key() == Qt::Key_Delete){ + emit clearMappings(); + } + SmTreeView::keyPressEvent(e); +} + MappingTreeResultView::MappingTreeResultView(QWidget *parent) : SmTreeView(parent) { setAlternatingRowColors(true); setPalette(qApp->palette()); } +void MappingTreeResultView::keyPressEvent(QKeyEvent *e){ + if(e->key() == Qt::Key_Left && (e->modifiers() & Qt::ControlModifier)){ + clearFocus(); + emit shiftFocus(); + return; + } + if(e->key() == Qt::Key_Left){ + emit removeMapping(); + } + SmTreeView::keyPressEvent(e); +} + MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ //the views mMappingTree = new MappingTreeWidget; @@ -298,13 +316,19 @@ MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ mMappingResult->setColumnHidden(1, true); mMappingResult->setColumnHidden(2, true); mMappingResult->setColumnHidden(3, true); - connect(mMappingResult->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(resultMappingChanged(QModelIndex,QModelIndex))); + connect(mMappingTree->mappingTreeView(), SIGNAL(addMapping()), this, SLOT(addMapping())); + connect(mMappingTree->mappingTreeView(), SIGNAL(clearMappings()), this, SLOT(clearMapping())); + connect(mMappingTree->mappingTreeView(), SIGNAL(shiftFocus()), this, SLOT(shiftFocusResult())); + connect(mMappingResult, SIGNAL(shiftFocus()), this, SLOT(shiftFocusMappings())); + connect(mMappingResult, SIGNAL(removeMapping()), this, SLOT(removeMapping())); //buttons mAddMapping = new QPushButton(tr(">>")); connect(mAddMapping, SIGNAL(clicked()), this, SLOT(addMapping())); mRemoveMapping = new QPushButton(tr("<<")); connect(mRemoveMapping, SIGNAL(clicked()), this, SLOT(removeMapping())); + mClearMapping = new QPushButton(tr("&Clear")); + connect(mClearMapping, SIGNAL(clicked()), this, SLOT(clearMapping())); //layout QHBoxLayout *mainLayout = new QHBoxLayout; @@ -313,16 +337,19 @@ MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ buttonLayout->addStretch(); buttonLayout->addWidget(mAddMapping); buttonLayout->addWidget(mRemoveMapping); + buttonLayout->addWidget(mClearMapping); buttonLayout->addStretch(); mainLayout->addLayout(buttonLayout); mainLayout->addWidget(mMappingResult); setLayout(mainLayout); + mMappingTree->mappingTreeView()->setFocus(); } void MappingEditWidget::addMapping(){ MappingData selected = mMappingTree->selectedItem(); mResultModel->addItem(selected); mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); } void MappingEditWidget::removeMapping(){ @@ -335,6 +362,12 @@ void MappingEditWidget::removeMapping(){ mResultModel->removeItem(firstIdx); } mMappingResult->expandAll(); + mMappingTree->mappingTreeView()->setFocus(); +} + +void MappingEditWidget::clearMapping(){ + mResultModel->clearData(); + mMappingTree->mappingTreeView()->setFocus(); } void MappingEditWidget::setMappings(const QList &mappings){ @@ -352,18 +385,12 @@ void MappingEditWidget::expandAllResults(){ mMappingResult->expandAll(); } -void MappingEditWidget::resultMappingChanged(const QModelIndex &cur, const QModelIndex &prev){ - Q_UNUSED(prev); - if(!cur.isValid()){ - return; - } - QModelIndex idx = cur; - QList path; - while(idx.isValid()){ - path << idx.data(MappingTreeResultModel::MappingIdRole).toInt(); - idx = idx.parent(); - } - mMappingTree->selectPath(path, false); +void MappingEditWidget::shiftFocusResult(){ + mMappingResult->setFocus(); +} + +void MappingEditWidget::shiftFocusMappings(){ + mMappingTree->mappingTreeView()->setFocus(); } MappingInputDialog::MappingInputDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ -- cgit v1.2.3-70-g09d2