summaryrefslogtreecommitdiffstats
path: root/mappingtreewidget.cpp
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2015-06-06 10:47:15 +0200
committerArno <arno@disconnect.de>2015-06-06 10:47:15 +0200
commit41e54bc5bded308687ad090afef9e5737edbe9b3 (patch)
treea5868d8ec8a551459c5ebdac9d155e70a4affdcc /mappingtreewidget.cpp
parent2b6a35559cc330fe0356a961e3283a11abc3442f (diff)
downloadSheMov-41e54bc5bded308687ad090afef9e5737edbe9b3.tar.gz
SheMov-41e54bc5bded308687ad090afef9e5737edbe9b3.tar.bz2
SheMov-41e54bc5bded308687ad090afef9e5737edbe9b3.zip
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
Diffstat (limited to 'mappingtreewidget.cpp')
-rw-r--r--mappingtreewidget.cpp71
1 files changed, 49 insertions, 22 deletions
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<int> &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<MappingData> &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<int> 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){