From c23dd354b9811956407da6d2eca3edbcc4999127 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 4 Jul 2013 11:06:28 -0300 Subject: Added a shortcut to 'esc', so it clears the selection or cancels the plan. Added a shortcut to the esc key, so it clears the selection, if there's no selection, it acts just like clicking on the 'cancel' button. Next: delete selected handlers. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 20 +++++++++++++++++++- qt-ui/diveplanner.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index a7bd0af4c..016a47e04 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -123,9 +123,27 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) connect(cancelBtn, SIGNAL(clicked()), this, SLOT(cancelClicked())); minMinutes = TIME_INITIAL_MAX; + + QAction *escAction = new QAction(this); + escAction->setShortcut(Qt::Key_Escape); + escAction->setShortcutContext(Qt::ApplicationShortcut); + addAction(escAction); + + connect(escAction, SIGNAL(triggered(bool)), this, SLOT(keyEscAction())); + setRenderHint(QPainter::Antialiasing); } +void DivePlannerGraphics::keyEscAction() +{ + if (scene()->selectedItems().count()){ + scene()->clearSelection(); + return; + } + + cancelClicked(); +} + qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation) { qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height(); @@ -419,7 +437,7 @@ void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event) if (event->modifiers().testFlag(Qt::ControlModifier)){ setSelected(true); } - // mousePressEvent 'grabs' the mouse and keyboard, annoying. + // mousePressEvent 'grabs' the mouse and keyboard, annoying. ungrabMouse(); ungrabKeyboard(); } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 9c8a2b7a6..310ef737c 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -77,6 +77,7 @@ protected: void deleteTemporaryDivePlan(struct divedatapoint* dp); qreal fromPercent(qreal percent, Qt::Orientation orientation); private slots: + void keyEscAction(); void increaseTime(); void increaseDepth(); void okClicked(); -- cgit v1.2.3-70-g09d2