From 932ee3da94856401477f1b3f1d58c26841f2bce8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 4 Jul 2013 11:16:42 -0300 Subject: Added a 'delete' action, with the keyboard. Added a delete action from the keyboard, there's also a possibility to add the same action from the menu, but I frankly don't like much the idea. so, to delete a handler now, you need to select it ( ctrl + click ) then press the delete button. Multiple delection is also possible. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 30 +++++++++++++++++++++++++----- qt-ui/diveplanner.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 016a47e04..6a721adf0 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -124,16 +124,36 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) minMinutes = TIME_INITIAL_MAX; - QAction *escAction = new QAction(this); - escAction->setShortcut(Qt::Key_Escape); - escAction->setShortcutContext(Qt::ApplicationShortcut); - addAction(escAction); + QAction *action = NULL; - connect(escAction, SIGNAL(triggered(bool)), this, SLOT(keyEscAction())); +#define ADD_ACTION( SHORTCUT, Slot ) \ + action = new QAction(this); \ + action->setShortcut( SHORTCUT ); \ + action->setShortcutContext(Qt::ApplicationShortcut); \ + addAction(action); \ + connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot )) + + ADD_ACTION(Qt::Key_Escape, keyEscAction()); + ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); +#undef ADD_ACTION setRenderHint(QPainter::Antialiasing); } +void DivePlannerGraphics::keyDeleteAction() +{ + if(scene()->selectedItems().count()){ + Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()){ + if (DiveHandler *handler = qgraphicsitem_cast(i)){ + handles.removeAll(handler); + scene()->removeItem(handler); + delete i; + } + } + createDecoStops(); + } +} + void DivePlannerGraphics::keyEscAction() { if (scene()->selectedItems().count()){ diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 310ef737c..c6869feb4 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -78,6 +78,7 @@ protected: qreal fromPercent(qreal percent, Qt::Orientation orientation); private slots: void keyEscAction(); + void keyDeleteAction(); void increaseTime(); void increaseDepth(); void okClicked(); -- cgit v1.2.3-70-g09d2