diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-05-24 12:39:40 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-24 09:07:34 -0700 |
commit | bc047238d4630c2090cbd424e26f6476b1cd435a (patch) | |
tree | 17a6da2c13d13d675cf6d194730a139631540d91 | |
parent | ba1c4fcec1760748846ff6ad14127409bed0a783 (diff) | |
download | subsurface-bc047238d4630c2090cbd424e26f6476b1cd435a.tar.gz |
Port the KeyPress actions to the new profile.
[Dirk Hohndel: combined two commits into one and cleaned up some
whitespace issues]
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/diveplanner.cpp | 138 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 7 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 2 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 179 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 9 |
5 files changed, 185 insertions, 150 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index b01cbf252..e6780c164 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -45,137 +45,9 @@ static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance() DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent) { - QAction *action = NULL; -#define ADD_ACTION(SHORTCUT, Slot) \ - action = new QAction(this); \ - action->setShortcut(SHORTCUT); \ - action->setShortcutContext(Qt::WindowShortcut); \ - addAction(action); \ - connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot)) - ADD_ACTION(Qt::Key_Escape, keyEscAction()); - 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 } -void DivePlannerGraphics::keyDownAction() -{ -#if 0 - Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { - if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { - int row = handles.indexOf(handler); - divedatapoint dp = plannerModel->at(row); - if (dp.depth >= depthLine->maximum()) - continue; - - dp.depth += M_OR_FT(1, 5); - plannerModel->editStop(row, dp); - } - } -#endif -} - -void DivePlannerGraphics::keyUpAction() -{ -#if 0 - Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { - if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { - int row = handles.indexOf(handler); - divedatapoint dp = plannerModel->at(row); - - if (dp.depth <= 0) - continue; - - dp.depth -= M_OR_FT(1, 5); - plannerModel->editStop(row, dp); - } - } - drawProfile(); -#endif -} - -void DivePlannerGraphics::keyLeftAction() -{ -#if 0 - Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { - if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { - int row = handles.indexOf(handler); - divedatapoint dp = plannerModel->at(row); - - if (dp.time / 60 <= 0) - continue; - - // don't overlap positions. - // maybe this is a good place for a 'goto'? - double xpos = timeLine->posAtValue((dp.time - 60) / 60); - bool nextStep = false; - Q_FOREACH (DiveHandler *h, handles) { - if (IS_FP_SAME(h->pos().x(), xpos)) { - nextStep = true; - break; - } - } - if (nextStep) - continue; - - dp.time -= 60; - plannerModel->editStop(row, dp); - } - } -#endif -} - -void DivePlannerGraphics::keyRightAction() -{ -#if 0 - Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { - if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { - int row = handles.indexOf(handler); - divedatapoint dp = plannerModel->at(row); - if (dp.time / 60 >= timeLine->maximum()) - continue; - - // don't overlap positions. - // maybe this is a good place for a 'goto'? - double xpos = timeLine->posAtValue((dp.time + 60) / 60); - bool nextStep = false; - Q_FOREACH (DiveHandler *h, handles) { - if (IS_FP_SAME(h->pos().x(), xpos)) { - nextStep = true; - break; - } - } - if (nextStep) - continue; - - dp.time += 60; - plannerModel->editStop(row, dp); - } - } -#endif -} - -void DivePlannerGraphics::keyDeleteAction() -{ -#if 0 - int selCount = scene()->selectedItems().count(); - if (selCount) { - QVector<int> selectedIndexes; - Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { - if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { - selectedIndexes.push_back(handles.indexOf(handler)); - } - } - plannerModel->removeSelectedPoints(selectedIndexes); - } -#endif -} - - bool intLessThan(int a, int b) { return a <= b; @@ -192,16 +64,6 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows) endRemoveRows(); } -void DivePlannerGraphics::keyEscAction() -{ - if (scene()->selectedItems().count()) { - scene()->clearSelection(); - return; - } - if (DivePlannerPointsModel::instance()->isPlanner()) - plannerModel->cancelPlan(); -} - void DivePlannerPointsModel::createSimpleDive() { // plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 42bf1544f..10c907b39 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -125,12 +125,7 @@ public: DivePlannerGraphics(QWidget *parent = 0); private slots: - void keyEscAction(); - void keyDeleteAction(); - void keyUpAction(); - void keyDownAction(); - void keyLeftAction(); - void keyRightAction(); + }; #include "ui_diveplanner.h" diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 1bde5f0e8..0aaab2a34 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -178,6 +178,4 @@ private: UpdateManager *updateManager; }; -MainWindow *mainWindow(); - #endif // MAINWINDOW_H diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index b1bf57f9f..413386ef2 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -99,6 +99,23 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), setEmptyState(); connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); + QAction *action = NULL; +#define ADD_ACTION(SHORTCUT, Slot) \ + action = new QAction(this); \ + action->setShortcut(SHORTCUT); \ + action->setShortcutContext(Qt::WindowShortcut); \ + addAction(action); \ + connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot)); \ + actionsForKeys[SHORTCUT] = action; + + ADD_ACTION(Qt::Key_Escape, keyEscAction()); + 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 + #ifndef QT_NO_DEBUG QTableView *diveDepthTableView = new QTableView(); diveDepthTableView->setModel(dataModel); @@ -664,6 +681,9 @@ void ProfileWidget2::setProfileState() return; disconnectTemporaryConnections(); + //TODO: Move the DC handling to another method. + MainWindow::instance()->enableDcShortcuts(); + currentState = PROFILE; MainWindow::instance()->setToolButtonsEnabled(true); toolTipItem->readPos(); @@ -725,6 +745,15 @@ void ProfileWidget2::setAddState() setProfileState(); disconnectTemporaryConnections(); + //TODO: Move this method to another place, shouldn't be on mainwindow. + MainWindow::instance()->disableDcShortcuts(); + actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left); + actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right); + actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up); + actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down); + actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape); + actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete); + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot())); connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot())); @@ -956,6 +985,11 @@ void ProfileWidget2::disconnectTemporaryConnections() this, SLOT(pointInserted(const QModelIndex &, int, int))); disconnect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(pointsRemoved(const QModelIndex &, int, int))); + + + Q_FOREACH (QAction *action, actionsForKeys.values()) { + action->setShortcut(QKeySequence()); + } } void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end) @@ -1015,12 +1049,12 @@ int ProfileWidget2::fixHandlerIndex(DiveHandler *activeHandler) if (index > 0 && index < handles.count() - 1) { DiveHandler *before = handles[index - 1]; if (before->pos().x() > activeHandler->pos().x()) { - handles.swap(index, index-1); + handles.swap(index, index - 1); return index - 1; } DiveHandler *after = handles[index + 1]; if (after->pos().x() < activeHandler->pos().x()) { - handles.swap(index, index+1); + handles.swap(index, index + 1); return index + 1; } } @@ -1029,7 +1063,7 @@ int ProfileWidget2::fixHandlerIndex(DiveHandler *activeHandler) void ProfileWidget2::recreatePlannedDive() { - DiveHandler *activeHandler = qobject_cast<DiveHandler*>(sender()); + DiveHandler *activeHandler = qobject_cast<DiveHandler *>(sender()); DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); int index = fixHandlerIndex(activeHandler); int mintime = 0, maxtime = (timeAxis->maximum() + 10) * 60; @@ -1043,8 +1077,145 @@ void ProfileWidget2::recreatePlannedDive() return; divedatapoint data = plannerModel->at(index); - data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);; + data.depth = rint(profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1); data.time = rint(timeAxis->valueAt(activeHandler->pos())); plannerModel->editStop(index, data); } + +void ProfileWidget2::keyDownAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { + int row = handles.indexOf(handler); + divedatapoint dp = plannerModel->at(row); + if (dp.depth >= profileYAxis->maximum()) + continue; + + dp.depth += M_OR_FT(1, 5); + plannerModel->editStop(row, dp); + } + } +} + +void ProfileWidget2::keyUpAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { + int row = handles.indexOf(handler); + divedatapoint dp = plannerModel->at(row); + + if (dp.depth <= 0) + continue; + + dp.depth -= M_OR_FT(1, 5); + plannerModel->editStop(row, dp); + } + } +} + +void ProfileWidget2::keyLeftAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { + int row = handles.indexOf(handler); + divedatapoint dp = plannerModel->at(row); + + if (dp.time / 60 <= 0) + continue; + + // don't overlap positions. + // maybe this is a good place for a 'goto'? + double xpos = timeAxis->posAtValue((dp.time - 60) / 60); + bool nextStep = false; + Q_FOREACH (DiveHandler *h, handles) { + if (IS_FP_SAME(h->pos().x(), xpos)) { + nextStep = true; + break; + } + } + if (nextStep) + continue; + + dp.time -= 60; + plannerModel->editStop(row, dp); + } + } +} + +void ProfileWidget2::keyRightAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { + int row = handles.indexOf(handler); + divedatapoint dp = plannerModel->at(row); + if (dp.time / 60 >= timeAxis->maximum()) + continue; + + // don't overlap positions. + // maybe this is a good place for a 'goto'? + double xpos = timeAxis->posAtValue((dp.time + 60) / 60); + bool nextStep = false; + Q_FOREACH (DiveHandler *h, handles) { + if (IS_FP_SAME(h->pos().x(), xpos)) { + nextStep = true; + break; + } + } + if (nextStep) + continue; + + dp.time += 60; + plannerModel->editStop(row, dp); + } + } +} + +void ProfileWidget2::keyDeleteAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + int selCount = scene()->selectedItems().count(); + if (selCount) { + QVector<int> selectedIndexes; + Q_FOREACH (QGraphicsItem *i, scene()->selectedItems()) { + if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(i)) { + selectedIndexes.push_back(handles.indexOf(handler)); + } + } + plannerModel->removeSelectedPoints(selectedIndexes); + } +} + +void ProfileWidget2::keyEscAction() +{ + if (currentState != ADD && currentState != PLAN) + return; + + if (scene()->selectedItems().count()) { + scene()->clearSelection(); + return; + } + + DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); + if (plannerModel->isPlanner()) + plannerModel->cancelPlan(); +} diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 5ce275eed..3c3d86d01 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -94,6 +94,14 @@ slots: // Necessary to call from QAction's signals. /* this is called for every move on the handlers. maybe we can speed up this a bit? */ void recreatePlannedDive(); + /* key press handlers */ + void keyEscAction(); + void keyDeleteAction(); + void keyUpAction(); + void keyDownAction(); + void keyLeftAction(); + void keyRightAction(); + protected: virtual void resizeEvent(QResizeEvent *event); virtual void wheelEvent(QWheelEvent *event); @@ -151,6 +159,7 @@ private: void repositionDiveHandlers(); int fixHandlerIndex(DiveHandler *activeHandler); friend class DiveHandler; + QHash<Qt::Key, QAction *> actionsForKeys; }; #endif // PROFILEWIDGET2_H |