MainWindow::MainWindow() { m_main = new MainArea(); QGraphicsView* view = new QGraphicsView(m_main, this); view->setOptimizationFlags( QGraphicsView::DontClipPainter | QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing ); // view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate ); view->setCacheMode( QGraphicsView::CacheBackground ); view->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff ); setCentralWidget(view); setupActions(); #ifndef Q_OS_QNX QLayout* l = layout(); Q_ASSERT(l); l->setSizeConstraint(QLayout::SetFixedSize); // setup status bar KStatusBar* bar = statusBar(); Q_ASSERT(bar); m_time_label = new QLabel(""); bar->addPermanentWidget(m_time_label); m_balls_label = new QLabel(""); bar->addWidget(m_balls_label); // bar->setItemAlignment(STATUSBAR_BALLS, Qt::AlignLeft); #endif connect(m_main, SIGNAL(changeGameTime(int)), this, SLOT(setGameTime(int))); connect(m_main, SIGNAL(changeBallNumber(int)), this, SLOT(setBallNumber(int))); connect(m_main, SIGNAL(changeState(bool)), this, SLOT(changeState(bool))); connect(m_main, SIGNAL(pause(bool)), this, SLOT(pause(bool))); #ifndef Q_OS_QNX stateChanged("playing", KXMLGUIClient::StateReverse); #endif connect(m_main, SIGNAL(starting()), this, SLOT(newGame())); connect(m_main, SIGNAL(gameOver(int)), this, SLOT(gameOver(int))); #ifndef Q_OS_QNX KGameDifficulty::init(this, this, SLOT(difficultyChanged(KGameDifficulty::standardLevel))); KGameDifficulty::setRestartOnChange(KGameDifficulty::RestartOnChange); KGameDifficulty::addStandardLevel(KGameDifficulty::Easy); KGameDifficulty::addStandardLevel(KGameDifficulty::Medium); KGameDifficulty::addStandardLevel(KGameDifficulty::Hard); KGameDifficulty::setLevel(KGameDifficulty::standardLevel(KollisionConfig::gameDifficulty())); #endif #ifdef Q_OS_QNX //setMinimumSize(m_main->sceneRect().size().toSize()); #endif }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); this->setWindowState(this->windowState() ^ Qt::WindowFullScreen); QGraphicsView *view = ui->graphicsView; view->setScene(&scene); view->setWindowFlags (Qt::FramelessWindowHint); view->setAlignment(Qt::AlignLeft | Qt::AlignTop); view->setRenderHint(QPainter::Antialiasing); view->setMaximumSize(size()); view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view->setCacheMode(QGraphicsView::CacheBackground); QGMenu *menu = new QGMenu(view->rect()); //menu->setOpacity(0); scene.addItem(menu); int size = 152 + 16; for (int i = 0; i < 20 ;i++) { int r = i / 5; int c = i % 5; QGTile *tile = new QGTile; scene.addItem(tile); tile->moveBy(c * size, r * size); tile->installSceneEventFilter(menu); } menu->setZValue(100); // QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20); // QTimeLine *timer = new QTimeLine(5000); // timer->setFrameRange(0, 100); // QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; // animation->setItem(ball); // animation->setTimeLine(timer); // for (int i = 0; i < 200; ++i) // animation->setPosAt(i / 200.0, QPointF(i, i)); // scene.addItem(ball); // timer->start(); }
int main (int argc, char** argv) { QApplication app(argc, argv); QGraphicsView view; QGraphicsScene *scene = new QGraphicsScene(&view); scene->setItemIndexMethod(QGraphicsScene::NoIndex); Line *left, *right, *right2; int of = pos_x; for(int i = 0; i < c; i++) { Line* ball = new Line(QPoint(of, -2)); scene->addItem(ball); of += size; if(i==0) left = ball; else if(i == c - 1) right = ball; else if(i == c - 2) right2 = ball; } QTimeLine *LeftTimerTo = newAnim(left,0,45,QEasingCurve::OutQuart); QTimeLine *LeftTimerReturn = newAnim(left,45,0,QEasingCurve::InQuart); QTimeLine *RightTimerTo = newAnim(right,0,-45,QEasingCurve::OutQuart); QTimeLine *RightTimerBack = newAnim(right,-45,0,QEasingCurve::InQuart); QTimeLine *RightTimerTo2 = newAnim(right2,0,-45,QEasingCurve::OutQuart); QTimeLine *RightTimerBack2 = newAnim(right2,-45,0,QEasingCurve::InQuart); scene->setSceneRect(0, 0, 940, 460); view.setCacheMode(QGraphicsView::CacheBackground); view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); view.setScene(scene); view.resize(960, 480); view.show(); QObject::connect(LeftTimerTo, SIGNAL(finished()), LeftTimerReturn, SLOT(start())); QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo, SLOT(start())); QObject::connect(LeftTimerReturn, SIGNAL(finished()), RightTimerTo2, SLOT(start())); QObject::connect(RightTimerTo, SIGNAL(finished()), RightTimerBack, SLOT(start())); QObject::connect(RightTimerTo2, SIGNAL(finished()), RightTimerBack2, SLOT(start())); QObject::connect(RightTimerBack,SIGNAL(finished()), LeftTimerTo, SLOT(start())); LeftTimerReturn->start(); return app.exec(); }
VideoPlayer::VideoPlayer(QWidget *parent) : QWidget(parent) , videoItem(0) { videoItem = new GraphicsItemRenderer; videoItem->resizeRenderer(640, 360); videoItem->setOutAspectRatioMode(VideoRenderer::RendererAspectRatio); QGraphicsScene *scene = new QGraphicsScene(this); scene->addItem(videoItem); QGraphicsView *graphicsView = new QGraphicsView(scene); #if 0 #ifndef QT_NO_OPENGL QGLWidget *glw = new QGLWidget(QGLFormat(QGL::SampleBuffers)); glw->setAutoFillBackground(false); graphicsView->setCacheMode(QGraphicsView::CacheNone); graphicsView->setViewport(glw); #endif #endif //0 QSlider *rotateSlider = new QSlider(Qt::Horizontal); rotateSlider->setRange(-180, 180); rotateSlider->setValue(0); connect(rotateSlider, SIGNAL(valueChanged(int)), this, SLOT(rotateVideo(int))); QPushButton *openBtn = new QPushButton; openBtn->setText("Open"); connect(openBtn, SIGNAL(clicked()), SLOT(open())); QBoxLayout *layout = new QVBoxLayout; layout->addWidget(graphicsView); layout->addWidget(rotateSlider); layout->addWidget(openBtn); setLayout(layout); mediaPlayer.setRenderer(videoItem); }