Added the left / right shortcuts for moving the handlers around in time.

Added the left / right shortcuts for moving the handlers around in time,
this also made me wonder why we have the 'previous dc' on the menu, it
got actually to broke my code on the shortcuts for the planner because
they are active everytime - should they be active only when the profile's
visible or they serve any other purpose?

If they serve only for the profile, I'll get them out of the  menu and
put them in their proper place - the profile view.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-07-04 12:30:05 -03:00
parent 52fd769efb
commit bb33be4117
4 changed files with 78 additions and 1 deletions

View file

@ -129,7 +129,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
#define ADD_ACTION( SHORTCUT, Slot ) \ #define ADD_ACTION( SHORTCUT, Slot ) \
action = new QAction(this); \ action = new QAction(this); \
action->setShortcut( SHORTCUT ); \ action->setShortcut( SHORTCUT ); \
action->setShortcutContext(Qt::ApplicationShortcut); \ action->setShortcutContext(Qt::WindowShortcut); \
addAction(action); \ addAction(action); \
connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot )) 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_Delete, keyDeleteAction());
ADD_ACTION(Qt::Key_Up, keyUpAction()); ADD_ACTION(Qt::Key_Up, keyUpAction());
ADD_ACTION(Qt::Key_Down, keyDownAction()); ADD_ACTION(Qt::Key_Down, keyDownAction());
ADD_ACTION(Qt::Key_Left, keyLeftAction());
ADD_ACTION(Qt::Key_Right, keyRightAction());
#undef ADD_ACTION #undef ADD_ACTION
setRenderHint(QPainter::Antialiasing); setRenderHint(QPainter::Antialiasing);
@ -174,6 +176,58 @@ void DivePlannerGraphics::keyUpAction()
createDecoStops(); 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() void DivePlannerGraphics::keyDeleteAction()
{ {
@ -438,6 +492,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
{ {
if (event->modifiers()){ if (event->modifiers()){
QGraphicsView::mousePressEvent(event); QGraphicsView::mousePressEvent(event);
return;
} }
QPointF mappedPos = mapToScene(event->pos()); QPointF mappedPos = mapToScene(event->pos());
@ -448,6 +503,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
originalHandlerPos = activeDraggedHandler->pos(); originalHandlerPos = activeDraggedHandler->pos();
} }
} }
QGraphicsView::mousePressEvent(event);
} }
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)

View file

@ -81,6 +81,8 @@ private slots:
void keyDeleteAction(); void keyDeleteAction();
void keyUpAction(); void keyUpAction();
void keyDownAction(); void keyDownAction();
void keyLeftAction();
void keyRightAction();
void increaseTime(); void increaseTime();
void increaseDepth(); void increaseDepth();
void okClicked(); void okClicked();

View file

@ -221,13 +221,27 @@ void MainWindow::on_actionPrint_triggered()
qDebug("actionPrint"); 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() void MainWindow::on_actionDivePlanner_triggered()
{ {
disableDcShortcuts();
ui->stackedWidget->setCurrentIndex(1); ui->stackedWidget->setCurrentIndex(1);
} }
void MainWindow::showProfile() void MainWindow::showProfile()
{ {
enableDcShortcuts();
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
} }

View file

@ -47,6 +47,11 @@ public:
void showError(QString message); void showError(QString message);
void setTitle(enum MainWindowTitleFormat format); void setTitle(enum MainWindowTitleFormat format);
// The 'Change DC Shortcuts' should only be enabled
// when the profile's visible.
void disableDcShortcuts();
void enableDcShortcuts();
private slots: private slots:
/* file menu action */ /* file menu action */
void on_actionNew_triggered(); void on_actionNew_triggered();