diff options
-rw-r--r-- | qt-ui/diveplanner.cpp | 58 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 2 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 14 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 5 |
4 files changed, 78 insertions, 1 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 083ddcfe8..f9420be2c 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -129,7 +129,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) #define ADD_ACTION( SHORTCUT, Slot ) \ action = new QAction(this); \ action->setShortcut( SHORTCUT ); \ - action->setShortcutContext(Qt::ApplicationShortcut); \ + action->setShortcutContext(Qt::WindowShortcut); \ addAction(action); \ connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot )) @@ -137,6 +137,8 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); ADD_ACTION(Qt::Key_Up, keyUpAction()); ADD_ACTION(Qt::Key_Down, keyDownAction()); + ADD_ACTION(Qt::Key_Left, keyLeftAction()); + ADD_ACTION(Qt::Key_Right, keyRightAction()); #undef ADD_ACTION setRenderHint(QPainter::Antialiasing); @@ -174,6 +176,58 @@ void DivePlannerGraphics::keyUpAction() createDecoStops(); } +void DivePlannerGraphics::keyLeftAction() +{ + Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()){ + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)){ + if (handler->sec / 60 <= 0) + continue; + + // don't overlap positions. + // maybe this is a good place for a 'goto'? + double xpos = timeLine->posAtValue((handler->sec - 60) / 60); + bool nextStep = false; + Q_FOREACH(DiveHandler *h, handles){ + if (h->pos().x() == xpos){ + nextStep = true; + break; + } + } + if(nextStep) + continue; + + handler->sec -= 60; + handler->setPos(xpos, handler->pos().y()); + } + } + createDecoStops(); +} + +void DivePlannerGraphics::keyRightAction() +{ + Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()){ + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)){ + if (handler->sec / 60 >= timeLine->maximum()) + continue; + + // don't overlap positions. + // maybe this is a good place for a 'goto'? + double xpos = timeLine->posAtValue((handler->sec + 60) / 60); + bool nextStep = false; + Q_FOREACH(DiveHandler *h, handles){ + if (h->pos().x() == xpos){ + nextStep = true; + break; + } + } + if(nextStep) + continue; + + handler->sec += 60; + handler->setPos(xpos, handler->pos().y()); + } + } createDecoStops(); +} void DivePlannerGraphics::keyDeleteAction() { @@ -438,6 +492,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) { if (event->modifiers()){ QGraphicsView::mousePressEvent(event); + return; } QPointF mappedPos = mapToScene(event->pos()); @@ -448,6 +503,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) originalHandlerPos = activeDraggedHandler->pos(); } } + QGraphicsView::mousePressEvent(event); } void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 5ea9f0dab..7f33f044b 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -81,6 +81,8 @@ private slots: void keyDeleteAction(); void keyUpAction(); void keyDownAction(); + void keyLeftAction(); + void keyRightAction(); void increaseTime(); void increaseDepth(); void okClicked(); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 90b2406cb..5bf190e78 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -221,13 +221,27 @@ void MainWindow::on_actionPrint_triggered() qDebug("actionPrint"); } +void MainWindow::disableDcShortcuts() +{ + ui->actionPreviousDC->setShortcut(QKeySequence()); + ui->actionNextDC->setShortcut(QKeySequence()); +} + +void MainWindow::enableDcShortcuts() +{ + ui->actionPreviousDC->setShortcut(Qt::Key_Left); + ui->actionNextDC->setShortcut(Qt::Key_Right); +} + void MainWindow::on_actionDivePlanner_triggered() { + disableDcShortcuts(); ui->stackedWidget->setCurrentIndex(1); } void MainWindow::showProfile() { + enableDcShortcuts(); ui->stackedWidget->setCurrentIndex(0); } diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 013c0dca7..a9f2ecaf0 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -47,6 +47,11 @@ public: void showError(QString message); void setTitle(enum MainWindowTitleFormat format); + // The 'Change DC Shortcuts' should only be enabled + // when the profile's visible. + void disableDcShortcuts(); + void enableDcShortcuts(); + private slots: /* file menu action */ void on_actionNew_triggered(); |