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 <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-07-04 11:16:42 -03:00
parent c23dd354b9
commit 932ee3da94
2 changed files with 26 additions and 5 deletions

View file

@ -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<DiveHandler*>(i)){
handles.removeAll(handler);
scene()->removeItem(handler);
delete i;
}
}
createDecoStops();
}
}
void DivePlannerGraphics::keyEscAction()
{
if (scene()->selectedItems().count()){

View file

@ -78,6 +78,7 @@ protected:
qreal fromPercent(qreal percent, Qt::Orientation orientation);
private slots:
void keyEscAction();
void keyDeleteAction();
void increaseTime();
void increaseDepth();
void okClicked();