<small></small>class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); QPoint start; QPoint end; ~MainWindow(); private: QGraphicsView* view; QGraphicsScene* scene; void keyPressEvent(QKeyEvent* k); MyQgraphicsObject* m; QPropertyAnimation* pr; QElapsedTimer* timer; int f; int u; int b; void forward(); void up(); void back(); void down(); }; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { view=new QGraphicsView; scene=new QGraphicsScene; m=new MyQgraphicsObject; pr=new QPropertyAnimation(m,"pos"); view->setScene(scene); view->resize(800,800); view->setFixedSize(800,800); setCentralWidget(view); scene->addItem(m); start= QPoint(0,0); f=30; u=-30; b=-30; } void MainWindow::keyPressEvent(QKeyEvent *k) { switch (k->key()) { case Qt::Key_J:{ forward(); break; } case Qt::Key_Z: { up(); down(); break; } case Qt::Key_F: { back(); break; } default: break; } } void MainWindow::forward() { end.setX(f); pr->setEndValue(end); pr->setDuration(1000); pr->setEasingCurve(QEasingCurve::Linear); pr->start(); f+=40; } void MainWindow::up() { end.setY(u); pr->setEndValue(end); pr->setDuration(1000); pr->setEasingCurve(QEasingCurve::Linear); pr->start(); u-=30; pr->pause(); } void MainWindow::back() { end.setX(b); pr->setEndValue(end); pr->setDuration(1000); pr->setEasingCurve(QEasingCurve::Linear); pr->start(); b-=40; } void MainWindow::down() { u+=30; end.setY(u); pr->setEndValue(end); pr->setDuration(1000); pr->setEasingCurve(QEasingCurve::Linear); pr->start(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)