View::View(QGraphicsScene *scene) : QGraphicsView(scene), m_timer(this) ,m_delay(30){ qDebug()<<"in View now"; QPixmap bgPix(":/images/koskipuisto_pieni.jpg"); m_pix = bgPix; setupWindow(); int h = height(); int y = qAbs(m_imageHeight-h)/2; setSceneRect(0, y, width(), h); m_sensors.append(InputController::QACCELEROMETER); m_sensors.append(InputController::QORIENTATIONSENSOR); m_sensors.append(InputController::QMAGNETOMETER); m_sensors.append(InputController::QROTATIONSENSOR); m_sensors.append(InputController::QTAPSENSOR); m_sensors.append(InputController::QCOMPASS); m_sensors.append(InputController::QKEYS); m_menu = new QMenu(this); createActions(); handleAction(NULL,InputController::QACCELEROMETER); m_timer.setSingleShot(false); m_timer.start(m_delay); connect(&m_timer, SIGNAL(timeout()), this, SLOT(update())); connect(this,SIGNAL(sceneRectChanged(QRectF)), this, SLOT(checkSensors(QRectF))); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setFixedSize(ui->graphicsView->width()+10,ui->graphicsView->height()+25); m_file = menuBar()->addMenu("Game"); m_help = menuBar()->addMenu("Help"); m_newGame = new QAction(tr("&New Game"),this); //m_settings = new QAction(tr("&Settings"),this); m_exit = new QAction(tr("E&xit"),this); m_about = new QAction(tr("About arkanoid"),this); m_newGame->setShortcut(QKeySequence::New); m_newGame->setShortcut(QKeySequence::Close); QPixmap bgPix(":/img/hexagon_pattern.png"); bgPix = bgPix.scaled(800,600, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); m_scene = new QGraphicsScene(0,0,ui->graphicsView->width(),ui->graphicsView->height()); ui->graphicsView->setScene(m_scene); QPixmap blft(":/img/border_left.png"); QPixmap btop(":/img/border_top.png"); QPixmap brght(":/img/border_right.png"); blft = blft.scaled(800,25, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); btop = btop.scaled(25,600, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); brght = brght.scaled(800,25, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); ui->graphicsView->setBackgroundBrush(bgPix); ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground); ui->graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QIcon ico(tr(":/icon.ico")); setWindowIcon(ico); connect(m_newGame,SIGNAL(triggered()),this,SLOT(startNewGame())); //connect(m_settings,SIGNAL(triggered()),this,SLOT(openSettings())); connect(m_exit,SIGNAL(triggered()),this,SLOT(close())); connect(m_about,SIGNAL(triggered()),this,SLOT(openAbout())); m_file->addAction(m_newGame); m_file->addSeparator(); //m_file->addAction(m_settings); //m_file->addSeparator(); m_file->addAction(m_exit); m_help->addAction(m_about); setCentralWidget(ui->graphicsView); }
void MusicLrcArtPhotoLabel::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); QPainter painter(this); QPixmap bgPix(":/image/imagetrans"); for(int i=0; i<ceil(width()/PIX_WIDTH); ++i) { for(int j=0; j<=ceil(height()/PIX_HEIGHT); ++j) { painter.drawPixmap(i*PIX_WIDTH, j*PIX_HEIGHT, PIX_WIDTH, PIX_HEIGHT, bgPix); } } m_imagePos.setX(m_imagePos.x() + m_deltaPos.x()); m_imagePos.setY(m_imagePos.y() + m_deltaPos.y()); painter.drawPixmap(m_imagePos.x(), m_imagePos.y(), m_width, m_height, m_showPix); painter.end(); }