moved the code && small alterations for them to work on the new profile.
From 5bfc5d84caf6aa666a703a2600d200e8cf9b8cba Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sat, 24 May 2014 12:39:40 -0300 Subject: [PATCH 9/9] Port the KeyPress actions to the new profile.
None of them are working, they are being called but for some reason, they are early returning. I'll try to hunt this down Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/diveplanner.cpp | 138 ------------------------------- qt-ui/diveplanner.h | 7 +- qt-ui/mainwindow.h | 2 - qt-ui/profile/profilewidget2.cpp | 171 +++++++++++++++++++++++++++++++++++++++ qt-ui/profile/profilewidget2.h | 9 +++ 5 files changed, 181 insertions(+), 146 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index b01cbf2..e6780c1 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 42bf154..10c907b 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 1bde5f0..0aaab2a 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 b1bf57f..6b587aa 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) @@ -1048,3 +1082,140 @@ void ProfileWidget2::recreatePlannedDive() 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(); +} \ No newline at end of file diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 5ce275e..069ec60 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 -- 1.9.3
From b8082ea4faad9debd85e17781caeeee95c6fa488 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sat, 24 May 2014 12:47:09 -0300 Subject: [PATCH 10/10] Change OR to AND on conditional I'm a bad programmer and forgot how to use conditionals, aparently... Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/profilewidget2.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 6b587aa..4bcfd9b 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -1085,7 +1085,7 @@ void ProfileWidget2::recreatePlannedDive() void ProfileWidget2::keyDownAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); @@ -1098,13 +1098,14 @@ void ProfileWidget2::keyDownAction() dp.depth += M_OR_FT(1, 5); plannerModel->editStop(row, dp); + qDebug() << "Editando."; } } } void ProfileWidget2::keyUpAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); @@ -1124,7 +1125,7 @@ void ProfileWidget2::keyUpAction() void ProfileWidget2::keyLeftAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); @@ -1157,7 +1158,7 @@ void ProfileWidget2::keyLeftAction() void ProfileWidget2::keyRightAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); @@ -1189,7 +1190,7 @@ void ProfileWidget2::keyRightAction() void ProfileWidget2::keyDeleteAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); @@ -1207,7 +1208,7 @@ void ProfileWidget2::keyDeleteAction() void ProfileWidget2::keyEscAction() { - if (currentState != ADD || currentState != PLAN) + if (currentState != ADD && currentState != PLAN) return; if (scene()->selectedItems().count()) { -- 1.9.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
