MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Space* mySpace = new Space(100); // SpaceGUI* spaceGUI = new SpaceGUI(mySpace); spaceGUI = new SpaceGUI(mySpace); //TODO: only for test mySpace->SetValue(1, 25); CAutomaton = new CellularAutomaton(mySpace); myRule = new RuleMoore(); CAutomaton->SetRule(myRule); ui->graphicsView->setAlignment(Qt::AlignLeft | Qt::AlignTop); QGraphicsScene* scene = new QGraphicsScene(ui->graphicsView); scene->setBackgroundBrush(Qt::green); ui->graphicsView->setScene(scene); scene->addItem(spaceGUI); }
Database_Tilesets::Database_Tilesets(QWidget *parent) : QWidget(parent) { QGraphicsScene *scene; setupUi(this); twTilesetList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); twTilesetList->horizontalHeader()->setHidden(true); twTilesetList->verticalHeader()->setHidden(true); twTerrainList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); twTerrainList->horizontalHeader()->setHidden(true); twTerrainList->verticalHeader()->setHidden(true); cboxPhase->setEnabled(false); gvTileEditor->changeView(TileView::VIEW_TERRAIN); tilesetRef = NULL; ignoreEvents = true; bTileGroupSideButton->setSpinBox(sbTileGroup); bFPSSideButton->setSpinBox(sbFPS); gvTilePreview->setBackgroundBrush(QBrush(QImage(":/icons/graphicsview_background.png"))); scene = new QGraphicsScene(0.0, 0.0, 32.0, 32.0); scene->setBackgroundBrush(QBrush(QImage(":/icons/graphicsview_background.png"))); gvTilePreview->setScene(scene); tilePreviewItem = new QGraphicsPixmapItem; tilePreviewItem->setPos(0.0, 0.0); tilePreviewItem->setVisible(false); scene->addItem(tilePreviewItem); tilePreviewTimer = new QTimer(this); tilePreviewFrame = 0; tilePreviewDir = 1; currentTileID = 0; QObject::connect(sbTileView, SIGNAL(rangeChanged(int, int)), gvTileEditor, SLOT(setScrollBarRange(int, int))); QObject::connect(sbTileView, SIGNAL(valueChanged(int)), gvTileEditor, SLOT(setScrollBarValue(int))); QObject::connect(tilePreviewTimer, SIGNAL(timeout()), this, SLOT(animateTilePreview())); }
void MainWindow::drawLines(std::vector<Point> points){ QGraphicsScene * scene = this->ui->gv_Visualizer->scene(); scene->clear(); QRect geo = this->ui->gv_Visualizer->rect(); scene->setBackgroundBrush(Qt::black); QPen pen; Point previous; for(std::vector<Point>::iterator it = points.begin(); it != points.end(); ++it){ if(it == points.begin()){ previous = *it; }else{ int alpha = 255; if((previous.r || previous.g || previous.b)){ pen = QPen(QColor(previous.r?255:0,previous.g?255:0,previous.b?255:0,alpha)); }else{ pen = QPen(QColor(0,255,0,70)); pen.setStyle(Qt::DashDotDotLine); } scene->addLine(previous.x*geo.width()/65535,previous.y*geo.height()/65535,(*it).x*geo.width()/65535,(*it).y*geo.height()/65535,pen); previous = *it; } } this->ui->gv_Visualizer->setScene(scene); this->ui->gv_Visualizer->update(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _elapsedSteps(0), ui(new Ui::MainWindow) { ui->setupUi(this); QGraphicsScene *scene = new QGraphicsScene(ui->graphicsView); scene->setBackgroundBrush(QBrush(QColor(255, 255, 255, 255))); ui->graphicsView->setScene(scene); #if defined(MOBILE) ui->surrenderButton->hide(); ui->newGameButton->hide(); ui->saveButton->hide(); ui->loadButton->hide(); ui->stepsLabel->hide(); ui->graphicsView->setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing); ui->graphicsView->setOptimizationFlag(QGraphicsView::DontSavePainterState); ui->graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); #else ui->menuBar->hide(); #endif #if defined(HAVE_OPENGL) ui->graphicsView->setViewport(new QGLWidget(ui->graphicsView)); #endif }
PlayScene::PlayScene(){ //creat a scene QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0,0,1024,768); scene->setBackgroundBrush(QBrush(QImage("D:/img/img/bg.png"))); //add a view QGraphicsView *view = new QGraphicsView(scene); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setFixedSize(1024,768); //add Rec Rec *rec = new Rec(); rec->setFlag(QGraphicsItem::ItemIsFocusable); rec->setFocus(); scene->addItem(rec); BlueHit *bluehit = new BlueHit(); scene->addItem(bluehit); bluehit->setPos(80,190); //QTimer *timer = new QTimer(); //QObject::connect(timer,SIGNAL(timeout()),bluehit,SLOT(create())); Drum *drum = new Drum(); scene->addItem(drum); drum->setPos(1000,250); //show the view view->show(); }
Feeding::Feeding(QWidget *parent) { QGraphicsScene * scene = new QGraphicsScene(NULL); scene->setSceneRect(0,0,600,480); setScene(scene); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFixedSize(600,481); setFocusPolicy(Qt::NoFocus); basket = new Basket(this); scene->addItem(basket); basket->setPos(225,425); basket->setFlag(QGraphicsItem::ItemIsFocusable); basket->setFocus(); scene->setFocusItem(basket); scene->clearFocus(); QTimer * spawnTimer = new QTimer(this); QObject::connect(spawnTimer,SIGNAL(timeout()),this,SLOT(spawn())); int spawnTime = 1500 + (rand() % 501); spawnTimer->start(spawnTime); score = new scoreFood(); scene->addItem(score); scene->setBackgroundBrush(QBrush(QImage(":/feeding/backgroundPark1.png"))); }
void ARehabMainWindow::resizeEvent(QResizeEvent * event) { QGraphicsScene * scene = ui.graphicsInicial->scene(); scene->setSceneRect(0, 0, ui.graphicsInicial->width(), ui.graphicsInicial->height()); float wImage = this->pixmapItemInitial->boundingRect().width(); float hImage = this->pixmapItemInitial->boundingRect().height(); float wGraphicsView = ui.graphicsInicial->width(); float hGraphicsView = ui.graphicsInicial->height(); float scaleH = hGraphicsView / hImage; pixmapItemInitial->setScale(scaleH); pixmapItemInitial->setPos((wGraphicsView / 2.0f) - (scaleH*wImage / 2.0f), 0); QRadialGradient gradient(wGraphicsView / 2.0f, hGraphicsView / 2.0f, hGraphicsView); gradient.setColorAt(0.95, QColor(200, 200, 200)); gradient.setColorAt(0.5, QColor(255, 255, 255)); gradient.setColorAt(0, QColor(255, 255, 255)); scene->setBackgroundBrush(QBrush(gradient)); proxyBtNuevo->setPos((wGraphicsView / 2.0f) - (btNew->width() / 2.0f), hGraphicsView / 2.0f); proxyBtLoad->setPos((wGraphicsView / 2.0f) - (btLoad->width() / 2.0f), 80 + (hGraphicsView / 2.0f)); proxyBtLoadResults->setPos((wGraphicsView / 2.0f) - (btLoadResults->width() / 2.0f), 160 + (hGraphicsView / 2.0f)); ui.graphicsInicial->update(); QMainWindow::resizeEvent(event); }
NodeStatInspector::NodeStatInspector(QWidget* parent) : QWidget(parent) { setWindowFlags(Qt::Tool); QGraphicsScene* scene = new QGraphicsScene(); scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white)); scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue)); scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red)); QPolygonF poly; poly << QPointF(78,100) << QPointF(78+8,100+8) << QPointF(78,100+16) << QPointF(78-8,100+8); scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green)); scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white)); QPen pen; pen.setStyle(Qt::DotLine); pen.setWidth(0); scene->addLine(78,26,78,60,pen); scene->addLine(78,76,38,100,pen); scene->addLine(78,76,78,100,pen); scene->addLine(78,76,118,100,pen); scene->addLine(135,10,145,10); scene->addLine(145,10,145,110); scene->addLine(145,60,135,60); scene->addLine(145,110,135,110); nodeDepthLabel = scene->addText("0"); nodeDepthLabel->setPos(150,20); subtreeDepthLabel = scene->addText("0"); subtreeDepthLabel->setPos(150,75); choicesLabel = scene->addText("0"); choicesLabel->setPos(45,57); solvedLabel = scene->addText("0"); solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); failedLabel = scene->addText("0"); failedLabel->setPos(30,120); openLabel = scene->addText("0"); openLabel->setPos(110,120); QGraphicsView* view = new QGraphicsView(scene); view->setRenderHints(view->renderHints() | QPainter::Antialiasing); view->show(); scene->setBackgroundBrush(Qt::white); boxLayout = new QVBoxLayout(); boxLayout->setContentsMargins(0,0,0,0); boxLayout->addWidget(view); setLayout(boxLayout); setWindowTitle("Gist node statistics"); setAttribute(Qt::WA_QuitOnClose, false); setAttribute(Qt::WA_DeleteOnClose, false); }
QGraphicsScene * ClusteredArranger::arrange(SegmentList const & segments) const { QGraphicsScene * arrangement = new QGraphicsScene(); QTime time; time.start(); // determine background Segment * background = determineBackground(segments); SegmentList segmentsWOBack = removeBackground(segments, background); arrangement->setBackgroundBrush(QBrush(QColor(background->color().toQRgb()))); segmentsWOBack.calculateFeatureVariances(); // initialize layout //initializeLayout(segmentsWOBack, segmentsWOBack.featX(), segmentsWOBack.featY()); initializeLayout(segmentsWOBack, xAxisBox->currentIndex(), yAxisBox->currentIndex()); // find clusters time.restart(); QList<SegmentList> clusters = meanShift(segmentsWOBack); qDebug("Segments clustered in %f seconds", time.restart()/1000.0); qDebug(" %d clusters found", clusters.size()); // refine clusters //int counter = 0; foreach (SegmentList cluster, clusters) { if (clusterBox->currentIndex() == 0) { refineLayoutCircles(cluster); } else if (clusterBox->currentIndex() == 1) { refineLayoutPiles(cluster); } // debug output /*QGraphicsScene scene; scene.setBackgroundBrush(QBrush(QColor(255, 255, 255))); foreach(Segment * const segment, cluster) { scene.addItem(segment->toQGraphicsItem()); // without the following line QPainter tends to crash scene.width(); } ++counter; saveScene(&scene, QString("Test%1.png").arg(counter, 2));*/ } // refine layout if (clusterBox->currentIndex() == 0) { refineLayoutByPlace(clusters); } else if (clusterBox->currentIndex() == 1) { refineLayoutBySize(clusters); } // convert the segments to QGraphicsItems and add to QGraphicsScene foreach(Segment const * const segment, segmentsWOBack) { arrangement->addItem(segment->toQGraphicsItem()); // without the following line QPainter tends to crash arrangement->width(); }
int main(int argc, char **argv) { Q_INIT_RESOURCE(stickman); QApplication app(argc, argv); StickMan *stickMan = new StickMan; stickMan->setDrawSticks(false); QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setHtml("<font color=\"white\"><b>Stickman</b>" "<p>" "Tell the stickman what to do!" "</p>" "<p><i>" "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" "</i></p>" "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." "</p></font>"); qreal w = textItem->boundingRect().width(); QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); QGraphicsScene scene; scene.addItem(stickMan); scene.addItem(textItem); scene.setBackgroundBrush(Qt::black); GraphicsView view; view.setRenderHints(QPainter::Antialiasing); view.setTransformationAnchor(QGraphicsView::NoAnchor); view.setScene(&scene); QRectF sceneRect = scene.sceneRect(); // making enough room in the scene for stickman to jump and die view.resize(sceneRect.width() + 100, sceneRect.height() + 100); view.setSceneRect(sceneRect); view.show(); view.setFocus(); LifeCycle cycle(stickMan, &view); cycle.setDeathAnimation(":/animations/dead.bin"); cycle.addActivity(":/animations/jumping.bin", Qt::Key_J); cycle.addActivity(":/animations/dancing.bin", Qt::Key_D); cycle.addActivity(":/animations/chilling.bin", Qt::Key_C); cycle.start(); return app.exec(); }
void ARehabMainWindow::loadGuiInitial(void) { float wGraphicsView = ui.graphicsInicial->width(); float hGraphicsView = ui.graphicsInicial->height(); ui.btHelp->setIcon(QPixmap(QString::fromUtf8(":/svg/help.svg"))); ui.btAbout->setIcon(QPixmap(QString::fromUtf8(":/svg/about.svg"))); ui.graphicsInicial->verticalScrollBar()->blockSignals(true); ui.graphicsInicial->horizontalScrollBar()->blockSignals(true); ui.graphicsInicial->setScene(new QGraphicsScene); QGraphicsScene * scene = ui.graphicsInicial->scene(); scene->setSceneRect(0, 0, ui.graphicsInicial->width(), ui.graphicsInicial->height()); QRadialGradient gradient(wGraphicsView / 2.0f, hGraphicsView / 2.0f, hGraphicsView); gradient.setColorAt(0.95, QColor(200, 200, 200)); gradient.setColorAt(0.5, QColor(255, 255, 255)); gradient.setColorAt(0, QColor(255, 255, 255)); scene->setBackgroundBrush(QBrush(gradient)); QPixmap pix1(":/images/banner.png"); this->pixmapItemInitial = scene->addPixmap(pix1); float wImage = this->pixmapItemInitial->boundingRect().width(); float hImage = this->pixmapItemInitial->boundingRect().height(); float scaleH = hGraphicsView / hImage; pixmapItemInitial->setTransformationMode(Qt::SmoothTransformation); pixmapItemInitial->setScale(scaleH); pixmapItemInitial->setPos((wGraphicsView / 2.0f) - (scaleH*wImage / 2.0f), 0); QFont btFont("Calibri", 16, QFont::Light); btNew = new QPushButton("Nuevo Ejercicio"); btNew->setMinimumSize(360, 60); btNew->setFont(btFont); proxyBtNuevo = scene->addWidget(btNew); btLoad = new QPushButton("Cargar Ejercicio"); btLoad->setMinimumSize(360, 60); btLoad->setFont(btFont); proxyBtLoad = scene->addWidget(btLoad); btLoadResults = new QPushButton("Cargar Resultados de Paciente"); btLoadResults->setMinimumSize(360, 60); btLoadResults->setFont(btFont); proxyBtLoadResults = scene->addWidget(btLoadResults); QGridLayout * layoutBottomFrame = reinterpret_cast<QGridLayout*>(ui.bottomFrame->layout()); if (layoutBottomFrame) { layoutBottomFrame->addWidget(this->guistatewidget, 0, 1); this->guistatewidget->hide(); } }
void QARehabFileControlWidget::loadSVGFiles(void) { QGraphicsScene * scene = this->scene(); scene->setSceneRect(0, 0, this->width(), this->height()); scene->setBackgroundBrush(QBrush(QColor(100, 100, 100, 255))); containerRect = new QGraphicsRectItem(0, 0, this->width(), this->height()); containerRect->setPen(Qt::NoPen); containerRect->setBrush(QBrush(QColor(200, 200, 200, 50), Qt::CrossPattern)); QPolygonF polygon; polygon.append(QPointF(80, 0)); polygon.append(QPointF(0, 80)); polygon.append(QPointF(400, 80)); polygon.append(QPointF(320, 0)); itemBtContainer = new QGraphicsPolygonItem(polygon, containerRect); itemBtContainer->setPen(Qt::NoPen); itemBtContainer->setBrush(QBrush(QColor(200, 200, 200, 100))); svgRestart = new QSVGInteractiveItem(":/svg/restart.svg", itemBtContainer); svgPlayPause = new QSVGInteractiveItem(":/svg/play.svg", itemBtContainer); svgPlayPause->setCheckable(true); svgKinectMaximize = new QSVGInteractiveItem(":/svg/maximize.svg", itemBtContainer); svgKinectMaximize->setCheckable(true); itemTimeline = new QGraphicsRectItem(0, 0, this->width() - 160, 5, containerRect); itemTimeline->setPen(Qt::NoPen); itemTimeline->setBrush(QBrush(QColor(200, 200, 255, 200))); itemCuttingInterval = new QGraphicsRectItem(0, 0, this->width() - 160, 20, containerRect); itemCuttingInterval->setPen(Qt::NoPen); itemCuttingInterval->setBrush(QBrush(QColor(100, 200, 0, 100))); svgLeftSelector = new QSVGInteractiveItem(":/svg/intervalLeft.svg", containerRect); svgRightSelector = new QSVGInteractiveItem(":/svg/intervalRight.svg", containerRect); QFont font("Verdana", 8); itemTXModelLeftValue = new QGraphicsSimpleTextItem("Left", this->svgLeftSelector); itemTXModelLeftValue->setFont(font); itemTXModelLeftValue->setPen(Qt::NoPen); itemTXModelLeftValue->setBrush(QBrush(QColor(200, 200, 200, 200))); itemTXModelRightValue = new QGraphicsSimpleTextItem("Right", this->svgRightSelector); itemTXModelRightValue->setFont(font); itemTXModelRightValue->setPen(Qt::NoPen); itemTXModelRightValue->setBrush(QBrush(QColor(200, 200, 200, 200))); itemTXModelRightValue->setText(QString::number(this->model.rightValue)); itemTXModelLeftValue->setText(QString::number(this->model.leftValue)); scene->addItem(containerRect); }
StepBox::StepBox(std::vector<Block> blocks, std::vector<QColor> colors, int blockWidth, QWidget *parent) : QGraphicsView(parent), blocks(blocks), colors(colors), blockWidth(blockWidth), state(NEXT) { QGraphicsScene *sc = new QGraphicsScene(); sc->setBackgroundBrush(Qt::transparent); sc->setSceneRect(-10, -10, 6 * blockWidth + 20, 9 * blockWidth + 20); setScene(sc); UI::init(this, false); this->setMinimumSize(6 * blockWidth + 20, 9 * blockWidth + 20); rects.resize(0); draw(); }
void SpinMirror::setFrame() { // Paint the left hand frame of the main spinbox. // Use the part to the left of the edit field, plus a slice at // the left of the edit field stretched for the rest of the width. // This avoids possibly grabbing text and displaying it in the // spin button area. QGraphicsScene* c = scene(); QStyleOptionSpinBox option; option.initFrom(mMainSpinbox); QRect r = spinBoxEditFieldRect(mMainSpinbox, option); bool rtl = QApplication::isRightToLeft(); QPixmap p; if (mMirrored) { int x = rtl ? 0 : mMainSpinbox->width() - width(); p = grabWidget(mMainSpinbox, QRect(x, 0, width(), height())); } else { // Grab a single pixel wide vertical slice through the main spinbox, between the // frame and edit field. bool oxygen = mMainSpinbox->style()->inherits("Oxygen::Style"); // KDE >= 4.4 Oxygen style bool oxygen1 = mMainSpinbox->style()->inherits("OxygenStyle"); // KDE <= 4.3 Oxygen style int editOffsetY = oxygen ? 5 : oxygen1 ? 6 : 2; // offset to edit field int editOffsetX = (oxygen || oxygen1) ? 4 : 2; // offset to edit field int x = rtl ? r.right() - editOffsetX : r.left() + editOffsetX; p = grabWidget(mMainSpinbox, QRect(x, 0, 1, height())); // Blot out edit field stuff from the middle of the slice QPixmap dot = grabWidget(mMainSpinbox, QRect(x, editOffsetY, 1, 1)); QPainter painter(&p); painter.drawTiledPixmap(0, editOffsetY, 1, height() - 2*editOffsetY, dot, 0, 0); painter.end(); // Horizontally fill the mirror widget with the vertical slice p = p.scaled(size()); // Grab the left hand border of the main spinbox, and draw it into the mirror widget. QRect endr = rect(); if (rtl) { int mr = mMainSpinbox->width() - 1; endr.setWidth(mr - r.right() + editOffsetX); endr.moveRight(mr); } else endr.setWidth(r.left() + editOffsetX); x = rtl ? width() - endr.width() : 0; mMainSpinbox->render(&p, QPoint(x, 0), endr, QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask); } c->setBackgroundBrush(p); }
Form::Form(QWidget *parent) : QWidget(parent) { this->setupUi(this); //connect( this->ui.pushButton, SIGNAL( clicked() ), this, SLOT(pushButton_SetLabelText()) ); QColor sceneBackgroundColor; sceneBackgroundColor.setRgb(153, 255, 0); QGraphicsScene* scene = new QGraphicsScene(); QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(sceneBackgroundColor); scene->setBackgroundBrush(brush); this->graphicsView->setScene(scene); }
Seperator::Seperator(bool hasArrow, int height, QWidget *parent) : QGraphicsView(parent) { QGraphicsScene *sc = new QGraphicsScene(); sc->setBackgroundBrush(Qt::transparent); sc->setSceneRect(-18, 0, 40, height); setScene(sc); UI::init(this, false); this->setMinimumSize(40, height); sc->addLine(0, 0, 0, height, QPen(QColor(100, 149, 199), 3)); if (hasArrow) { QGraphicsPixmapItem * arrow = new QGraphicsPixmapItem(QPixmap("./data/makeAndBreak/BlueNext.png")); arrow->setPos(-18, height / 2 - 20); sc->addItem(arrow); } }
Game::Game(QWidget *parent) { QRect rec = QApplication::desktop()->screenGeometry(); int height = rec.height(); int width = rec.width(); QGraphicsScene *scene = new QGraphicsScene(); scene->setSceneRect(0,0,width,height); QGraphicsView *view = new QGraphicsView(scene); scene->setBackgroundBrush(QImage("://img/bg.png")); //player ship *player=new ship(); scene->addItem(player); player->setPos(width/2, height-70); //scoring score = new Score(); scene->addItem(score); //life life = new Life(); life->setPos(life->x(),life->y()+25); scene->addItem(life); player->setFlag(QGraphicsItem::ItemIsFocusable); player->setFocus(); //enemies QTimer*timer=new QTimer(); QObject::connect(timer,SIGNAL(timeout()),player,SLOT(spawn())); timer->start(2000); //music QMediaPlayer * music = new QMediaPlayer(); music->setMedia(QUrl("qrc:/sounds/bgmusic.mp3")); music->play(); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->showFullScreen(); }
void MainWindow::showCurrentFrame() { cv::Mat frame = vmstream.getCurrentFrame(); if (frame.empty()) { stop(); return; } int w = frame.cols, h = frame.rows; QImage image(frame.data, w, h, QImage::Format_RGB888); double dw = double(w)/ui->videoFrame->width(); double dh = double(h)/ui->videoFrame->height(); double scale = MAX(dw, dh); image = image.scaled(floor(w/scale), floor(h/scale)); QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(image)); QGraphicsScene* oldScene = ui->videoFrame->scene(); QGraphicsScene* scene = new QGraphicsScene(ui->videoFrame); scene->setBackgroundBrush(QBrush(Qt::black)); scene->addItem(pixmapItem); ui->videoFrame->setScene(scene); delete oldScene; ui->frameLabel->setText(QString::number(vmstream.getCurrentFrameNumber())); if (coordinatesIsNeeded) { GpsCoordinates coords = vmstream.getCurrentCoordinates(); ui->coord_x->setText(QString::number(coords.first)); ui->coord_y->setText(QString::number(coords.second)); if (vmstream.hasSpeed()) { float speed = vmstream.getCurrentSpeed(); ui->speedLabel->setText(QString::number(speed)); } } else { clearDataLabels(); } updateVideSlider(); }
MainWindowSample::MainWindowSample(Controller* modelController, QWidget *parent) : QWidget(parent), ui(new Ui::MainWindowSample) { ui->setupUi(this); ViewController* controller = new ViewController(modelController, this); QGraphicsScene * scene = new QGraphicsScene(this); scene->setBackgroundBrush(Qt::darkGray); Field * middleField = modelController -> getModelBoard() -> getMiddleField(); gui::Board * board = new gui::Board(controller, middleField); board -> setPos(0, 0); scene -> addItem(board); ui->graphicsView->setScene(scene); ui->graphicsView->show(); }
int main(int argc, char **argv) { QApplication app(argc, argv); QGraphicsScene scene; scene.setSceneRect(0,0,854,480); QGraphicsView view(&scene); view.viewport()->setAttribute(Qt::WA_AcceptTouchEvents); view.setFixedSize(854,480); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setStyleSheet( "QGraphicsView { border-style: none; }" ); scene.setBackgroundBrush(QBrush(QColor(100,100,100), Qt::SolidPattern)); QSvgRenderer *m_renderer = new QSvgRenderer(); m_renderer->load(QString(":/images/joystick.svg")); QGraphicsSvgItem *m_logo = new QGraphicsSvgItem(); m_logo->setSharedRenderer(m_renderer); m_logo->setElementId(QString("opheader")); m_logo->setPos(283,415); scene.addItem(m_logo); //inverted left and right Joystick *left = new Joystick(464,65,350,350,false,true); scene.addItem(left); Joystick *right = new Joystick(38,65,350,350,true,true); scene.addItem(right); cccom teste; QObject::connect(left,SIGNAL(JoystickUpdate(int,int)),&teste,SLOT(updateSticksTY(int,int))); QObject::connect(right,SIGNAL(JoystickUpdate(int,int)),&teste,SLOT(updateSticksPR(int,int))); view.showFullScreen(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QGraphicsScene scene; scene.setBackgroundBrush(Qt::black); CubeItem *item = new CubeItem(); item->setRect(0, 0, 600, 480); item->camera()->setEye(QVector3D(-5.0f, 3.0f, 6.0f)); scene.addItem(item); item->setFocus(); Graph graph; item->setScene(graph.scene()); QGLFormat format(QGLFormat::defaultFormat()); format.setSampleBuffers(true); QGraphicsView view(&scene); view.setViewport(new QGLWidget(format)); view.show(); return app.exec(); }
Designer::Designer(MainWindow *mw, QWidget *parent) : QGraphicsView(parent), timerId(0) { layout = new QGridLayout(); QGraphicsScene *scene = new QGraphicsScene(); scene->setBackgroundBrush(QBrush(UI::DARK_BLUE)); this->setScene(scene); layout->setRowMinimumHeight(5, 20); layout->setRowStretch(0, 1); layout->setRowStretch(7, 1); layout->setColumnStretch(0, 1); layout->setColumnStretch(9, 1); //BUILDING AREA mainWindow = mw; buildingArea = new BuildingArea(this); layout->addWidget(buildingArea, 1, 5, 4, 1); //LOGO logo = new QLabel(); logo->setPixmap(QPixmap("./data/makeAndBreak/RI_logo.png")); layout->addWidget(logo, 6, 1, 1, 1, Qt::AlignCenter); //INSTRUCTIONS initInstructions(); //BUTTON initButton(); //INFO info = new InfoPanel(); layout->addWidget(info, 6, 3, 1, 5); updateCV(); this->setLayout(layout); }
int main(int argc, char **argv) { Q_INIT_RESOURCE(stickman); QApplication app(argc, argv); StickMan *stickMan = new StickMan; stickMan->setDrawSticks(false); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) RectButton *buttonJump = new RectButton("Jump"); buttonJump->setPos(100, 125); RectButton *buttonDance = new RectButton("Dance"); buttonDance->setPos(100, 200); RectButton *buttonChill = new RectButton("Chill"); buttonChill->setPos(100, 275); #else QGraphicsTextItem *textItem = new QGraphicsTextItem(); textItem->setHtml("<font color=\"white\"><b>Stickman</b>" "<p>" "Tell the stickman what to do!" "</p>" "<p><i>" "<li>Press <font color=\"purple\">J</font> to make the stickman jump.</li>" "<li>Press <font color=\"purple\">D</font> to make the stickman dance.</li>" "<li>Press <font color=\"purple\">C</font> to make him chill out.</li>" "<li>When you are done, press <font color=\"purple\">Escape</font>.</li>" "</i></p>" "<p>If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again." "</p></font>"); qreal w = textItem->boundingRect().width(); QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect(); textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0); #endif QGraphicsScene scene; scene.addItem(stickMan); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) scene.addItem(buttonJump); scene.addItem(buttonDance); scene.addItem(buttonChill); #else scene.addItem(textItem); #endif scene.setBackgroundBrush(Qt::black); GraphicsView view; view.setRenderHints(QPainter::Antialiasing); view.setTransformationAnchor(QGraphicsView::NoAnchor); view.setScene(&scene); QRectF sceneRect = scene.sceneRect(); // making enough room in the scene for stickman to jump and die view.resize(sceneRect.width() + 100, sceneRect.height() + 100); view.setSceneRect(sceneRect); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.showMaximized(); view.fitInView(scene.sceneRect(), Qt::KeepAspectRatio); #else view.show(); view.setFocus(); #endif LifeCycle cycle(stickMan, &view); cycle.setDeathAnimation(":/animations/dead"); #if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) cycle.addActivity(":/animations/jumping", Qt::Key_J, buttonJump, SIGNAL(clicked())); cycle.addActivity(":/animations/dancing", Qt::Key_D, buttonDance, SIGNAL(clicked())); cycle.addActivity(":/animations/chilling", Qt::Key_C, buttonChill, SIGNAL(clicked())); #else cycle.addActivity(":/animations/jumping", Qt::Key_J); cycle.addActivity(":/animations/dancing", Qt::Key_D); cycle.addActivity(":/animations/chilling", Qt::Key_C); #endif cycle.start(); return app.exec(); }
//! [0] PadNavigator::PadNavigator(const QSize &size, QWidget *parent) : QGraphicsView(parent) { //! [0] //! [1] // Splash item SplashItem *splash = new SplashItem; splash->setZValue(1); //! [1] //! [2] // Pad item FlippablePad *pad = new FlippablePad(size); QGraphicsRotation *flipRotation = new QGraphicsRotation(pad); QGraphicsRotation *xRotation = new QGraphicsRotation(pad); QGraphicsRotation *yRotation = new QGraphicsRotation(pad); flipRotation->setAxis(Qt::YAxis); xRotation->setAxis(Qt::YAxis); yRotation->setAxis(Qt::XAxis); pad->setTransformations(QList<QGraphicsTransform *>() << flipRotation << xRotation << yRotation); //! [2] //! [3] // Back (proxy widget) item QGraphicsProxyWidget *backItem = new QGraphicsProxyWidget(pad); QWidget *widget = new QWidget; form.setupUi(widget); form.hostName->setFocus(); backItem->setWidget(widget); backItem->setVisible(false); backItem->setFocus(); backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); const QRectF r = backItem->rect(); backItem->setTransform(QTransform() .rotate(180, Qt::YAxis) .translate(-r.width()/2, -r.height()/2)); //! [3] //! [4] // Selection item RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray, pad); selectionItem->setZValue(0.5); //! [4] //! [5] // Splash animations QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y"); QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity"); smoothSplashMove->setEasingCurve(QEasingCurve::InQuad); smoothSplashMove->setDuration(250); smoothSplashOpacity->setDuration(250); //! [5] //! [6] // Selection animation QPropertyAnimation *smoothXSelection = new QPropertyAnimation(selectionItem, "x"); QPropertyAnimation *smoothYSelection = new QPropertyAnimation(selectionItem, "y"); QPropertyAnimation *smoothXRotation = new QPropertyAnimation(xRotation, "angle"); QPropertyAnimation *smoothYRotation = new QPropertyAnimation(yRotation, "angle"); smoothXSelection->setDuration(125); smoothYSelection->setDuration(125); smoothXRotation->setDuration(125); smoothYRotation->setDuration(125); smoothXSelection->setEasingCurve(QEasingCurve::InOutQuad); smoothYSelection->setEasingCurve(QEasingCurve::InOutQuad); smoothXRotation->setEasingCurve(QEasingCurve::InOutQuad); smoothYRotation->setEasingCurve(QEasingCurve::InOutQuad); //! [6] //! [7] // Flip animation setup QPropertyAnimation *smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle"); QPropertyAnimation *smoothFlipScale = new QPropertyAnimation(pad, "scale"); QPropertyAnimation *smoothFlipXRotation = new QPropertyAnimation(xRotation, "angle"); QPropertyAnimation *smoothFlipYRotation = new QPropertyAnimation(yRotation, "angle"); QParallelAnimationGroup *flipAnimation = new QParallelAnimationGroup(this); smoothFlipScale->setDuration(500); smoothFlipRotation->setDuration(500); smoothFlipXRotation->setDuration(500); smoothFlipYRotation->setDuration(500); smoothFlipScale->setEasingCurve(QEasingCurve::InOutQuad); smoothFlipRotation->setEasingCurve(QEasingCurve::InOutQuad); smoothFlipXRotation->setEasingCurve(QEasingCurve::InOutQuad); smoothFlipYRotation->setEasingCurve(QEasingCurve::InOutQuad); smoothFlipScale->setKeyValueAt(0, qvariant_cast<qreal>(1.0)); smoothFlipScale->setKeyValueAt(0.5, qvariant_cast<qreal>(0.7)); smoothFlipScale->setKeyValueAt(1, qvariant_cast<qreal>(1.0)); flipAnimation->addAnimation(smoothFlipRotation); flipAnimation->addAnimation(smoothFlipScale); flipAnimation->addAnimation(smoothFlipXRotation); flipAnimation->addAnimation(smoothFlipYRotation); //! [7] //! [8] // Flip animation delayed property assignment QSequentialAnimationGroup *setVariablesSequence = new QSequentialAnimationGroup; QPropertyAnimation *setFillAnimation = new QPropertyAnimation(pad, "fill"); QPropertyAnimation *setBackItemVisibleAnimation = new QPropertyAnimation(backItem, "visible"); QPropertyAnimation *setSelectionItemVisibleAnimation = new QPropertyAnimation(selectionItem, "visible"); setFillAnimation->setDuration(0); setBackItemVisibleAnimation->setDuration(0); setSelectionItemVisibleAnimation->setDuration(0); setVariablesSequence->addPause(250); setVariablesSequence->addAnimation(setBackItemVisibleAnimation); setVariablesSequence->addAnimation(setSelectionItemVisibleAnimation); setVariablesSequence->addAnimation(setFillAnimation); flipAnimation->addAnimation(setVariablesSequence); //! [8] //! [9] // Build the state machine QStateMachine *stateMachine = new QStateMachine(this); QState *splashState = new QState(stateMachine); QState *frontState = new QState(stateMachine); QHistoryState *historyState = new QHistoryState(frontState); QState *backState = new QState(stateMachine); //! [9] //! [10] frontState->assignProperty(pad, "fill", false); frontState->assignProperty(splash, "opacity", 0.0); frontState->assignProperty(backItem, "visible", false); frontState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(0.0)); frontState->assignProperty(selectionItem, "visible", true); backState->assignProperty(pad, "fill", true); backState->assignProperty(backItem, "visible", true); backState->assignProperty(xRotation, "angle", qvariant_cast<qreal>(0.0)); backState->assignProperty(yRotation, "angle", qvariant_cast<qreal>(0.0)); backState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(180.0)); backState->assignProperty(selectionItem, "visible", false); stateMachine->addDefaultAnimation(smoothXRotation); stateMachine->addDefaultAnimation(smoothYRotation); stateMachine->addDefaultAnimation(smoothXSelection); stateMachine->addDefaultAnimation(smoothYSelection); stateMachine->setInitialState(splashState); //! [10] //! [11] // Transitions QEventTransition *anyKeyTransition = new QEventTransition(this, QEvent::KeyPress, splashState); anyKeyTransition->setTargetState(frontState); anyKeyTransition->addAnimation(smoothSplashMove); anyKeyTransition->addAnimation(smoothSplashOpacity); //! [11] //! [12] QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Enter, backState); QKeyEventTransition *returnTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Return, backState); QKeyEventTransition *backEnterTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Enter, frontState); QKeyEventTransition *backReturnTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Return, frontState); enterTransition->setTargetState(historyState); returnTransition->setTargetState(historyState); backEnterTransition->setTargetState(backState); backReturnTransition->setTargetState(backState); enterTransition->addAnimation(flipAnimation); returnTransition->addAnimation(flipAnimation); backEnterTransition->addAnimation(flipAnimation); backReturnTransition->addAnimation(flipAnimation); //! [12] //! [13] // Create substates for each icon; store in temporary grid. int columns = size.width(); int rows = size.height(); QVector< QVector< QState * > > stateGrid; stateGrid.resize(rows); for (int y = 0; y < rows; ++y) { stateGrid[y].resize(columns); for (int x = 0; x < columns; ++x) stateGrid[y][x] = new QState(frontState); } frontState->setInitialState(stateGrid[0][0]); selectionItem->setPos(pad->iconAt(0, 0)->pos()); //! [13] //! [14] // Enable key navigation using state transitions for (int y = 0; y < rows; ++y) { for (int x = 0; x < columns; ++x) { QState *state = stateGrid[y][x]; QKeyEventTransition *rightTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Right, state); QKeyEventTransition *leftTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Left, state); QKeyEventTransition *downTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Down, state); QKeyEventTransition *upTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Up, state); rightTransition->setTargetState(stateGrid[y][(x + 1) % columns]); leftTransition->setTargetState(stateGrid[y][((x - 1) + columns) % columns]); downTransition->setTargetState(stateGrid[(y + 1) % rows][x]); upTransition->setTargetState(stateGrid[((y - 1) + rows) % rows][x]); //! [14] //! [15] RoundRectItem *icon = pad->iconAt(x, y); state->assignProperty(xRotation, "angle", -icon->x() / 6.0); state->assignProperty(yRotation, "angle", icon->y() / 6.0); state->assignProperty(selectionItem, "x", icon->x()); state->assignProperty(selectionItem, "y", icon->y()); frontState->assignProperty(icon, "visible", true); backState->assignProperty(icon, "visible", false); QPropertyAnimation *setIconVisibleAnimation = new QPropertyAnimation(icon, "visible"); setIconVisibleAnimation->setDuration(0); setVariablesSequence->addAnimation(setIconVisibleAnimation); } } //! [15] //! [16] // Scene QGraphicsScene *scene = new QGraphicsScene(this); scene->setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg")); scene->setItemIndexMethod(QGraphicsScene::NoIndex); scene->addItem(pad); scene->setSceneRect(scene->itemsBoundingRect()); setScene(scene); //! [16] //! [17] // Adjust splash item to scene contents const QRectF sbr = splash->boundingRect(); splash->setPos(-sbr.width() / 2, scene->sceneRect().top() - 2); frontState->assignProperty(splash, "y", splash->y() - 100.0); scene->addItem(splash); //! [17] //! [18] // View setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setMinimumSize(50, 50); setViewportUpdateMode(FullViewportUpdate); setCacheMode(CacheBackground); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); #ifndef QT_NO_OPENGL setViewport(new QOpenGLWidget); #endif stateMachine->start(); //! [18] }
Creator::Creator(QApplication &app) { //播放音乐文件 media = new Phonon::MediaObject(); audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory);//声音 Phonon::createPath(media, audioOutput); sourceList.append(QString("music/infinity.wma")); //建立pad pad = new RoundRectItem(QRectF(QPointF(0,0),QPointF(0,0)),QColor(0,0,255,0)); pad->setZValue(0); //设置backwindow backWindow = new QGraphicsProxyWidget(pad); backWidget = new BackWidget(); backWindow->setX(0); backWindow->setY(0); // backWindow->widget()->setWindowOpacity(1); backWindow->setWidget(backWidget); backWindow->setZValue(0); //设置开始窗口按钮 beginWindow = new QGraphicsProxyWidget(pad); beginWidget = new BeginBottum; beginWindow->setWidget(beginWidget); beginWindow->setX(backWindow->x()+400); beginWindow->setY(backWindow->y()+200); beginWindow->widget()->setWindowOpacity(1); beginWindow->setZValue(0.5); //设置音乐按键 musicWindow = new QGraphicsProxyWidget(pad); musicWidget = new ClickBottum; musicWindow->setWidget(musicWidget); musicWindow->setX(backWindow->widget()->width()-120); musicWindow->setY(backWindow->y()+20); musicWindow->widget()->setWindowOpacity(1); musicWindow->setZValue(0.9); //设置AI对战窗口 aiWindow = new QGraphicsProxyWidget(pad); aiWidget = new AIvsAI(); aiWindow->setWidget(aiWidget); aiWindow->setX(backWindow->x()); aiWindow->setY(backWindow->y()); aiWindow->widget()->setWindowOpacity(0); aiWindow->setZValue(0.5); //按钮控件 singleWindow = new QGraphicsProxyWidget(pad); singleWidget = new widgetssingle; singleWindow->setWidget(singleWidget); singleWindow->setX(backWindow->x()+400); singleWindow->setY(backWindow->y()+200); singleWindow->widget()->setWindowOpacity(0); singleWindow->setZValue(0.5); //回放器 replayerWindow = new QGraphicsProxyWidget(pad); replayerWidget = new ReplayWindow(); replayerWindow->setWidget(replayerWidget); replayerWindow->setX(backWindow->x()); replayerWindow->setY(backWindow->y()); replayerWindow->widget()->setWindowOpacity(0); replayerWindow->setZValue(0.5); //地图编辑器 mapEditWindow = new QGraphicsProxyWidget(pad); mapWideget = new MapEditor(); mapEditWindow->setWidget(mapWideget); mapEditWindow->setX(backWindow->x()); mapEditWindow->setY(backWindow->y()); mapEditWindow->widget()->setWindowOpacity(0); mapEditWindow->setZValue(0.5); //人机对战 humanaiWindow = new QGraphicsProxyWidget(pad); humanaiWidget = new humanai(); humanaiWindow->setX(backWindow->x()); humanaiWindow->setY(backWindow->y()); humanaiWindow->setWidget(humanaiWidget); humanaiWindow->widget()->setWindowOpacity(0); humanaiWindow->setZValue(0.5); //制作团队 teamMeneWindow = new QGraphicsProxyWidget(pad); teamMeneWideget = new TeamMenu(); teamMeneWindow->setWidget(teamMeneWideget); teamMeneWindow->setX(backWindow->x()); teamMeneWindow->setY(backWindow->y()); teamMeneWindow->widget()->setWindowOpacity(1); teamMeneWindow->setZValue(0.5); teamWindow = new QGraphicsProxyWidget(pad); teamWideget = new ProductionTeam(); teamWindow->setWidget(teamWideget); teamWindow->widget()->setWindowOpacity(1); teamWindow->setZValue(0.5); teamWideget->setAutoFillBackground(true); QPalette Tpalette = teamWindow->palette(); Tpalette.setBrush(QPalette::Window, QBrush(Qt::black)); teamWindow->setPalette(Tpalette); //登陆 LogInWindow = new QGraphicsProxyWidget(pad); logInwidget = new LogInWidget(); LogInWindow->setWidget(logInwidget); LogInWindow->widget()->setWindowOpacity(0); LogInWindow->setZValue(0.5); LogInWindow->setX(0); LogInWindow->setY(0); //测试赛 TestWindow = new QGraphicsProxyWidget(pad); testwidget = new TestWidget(); TestWindow->setWidget(testwidget); TestWindow->widget()->setWindowOpacity(0); TestWindow->setZValue(0.5); TestWindow->setX(0); TestWindow->setY(0); // beginWindow->close(); aiWindow->close(); singleWindow->close(); replayerWindow->close(); teamMeneWindow->close(); teamWindow->close(); mapEditWindow->close(); humanaiWindow->close(); LogInWindow->close(); TestWindow->close(); QObject::connect(beginWidget->returnUi()->exitmain,SIGNAL(clicked()),this,SLOT(close())); QObject::connect(beginWidget->returnUi()->startsingle,SIGNAL(clicked()),this,SLOT(BeginToSingle())); connect(this->singleWidget->ui->returnpre,SIGNAL(clicked()),this,SLOT(SingleToBegin())); connect(this->singleWidget->ui->aivsai,SIGNAL(clicked()),this,SLOT(SingleToAi())); connect(this->aiWidget->ui->ReturnPre,SIGNAL(clicked()),this,SLOT(AiToSingle())); connect(this->singleWidget->ui->replay,SIGNAL(clicked()),this,SLOT(SingleToReplayer())); connect(this->replayerWidget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(ReplayerToSingle())); connect(this->beginWidget->returnUi()->team,SIGNAL(clicked()),this,SLOT(BeginToTeam())); connect(this->teamMeneWideget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(TeamToBegin())); connect(this->musicWidget->ui->checkBox,SIGNAL(clicked()),this,SLOT(Music())); connect(this->replayerWidget->returnUi()->pushButton,SIGNAL(clicked()),this->replayerWidget,SLOT(GoInto())); connect(this->mapWideget->returnUi()->pushButton_5,SIGNAL(clicked()),this,SLOT(MapToSingle())); connect(this->singleWidget->ui->mapedit,SIGNAL(clicked()), this, SLOT(SingLeToMap())); connect(this->singleWidget->ui->playervsai,SIGNAL(clicked()),this,SLOT(SingleToHumanai())); connect(this->singleWidget->ui->playervsai, SIGNAL(clicked()), humanaiWidget, SLOT(initEmpty())); connect(this->humanaiWidget->returnUi()->Button_back, SIGNAL(clicked()), this, SLOT(HumanaiToSingle())); connect(this->media,SIGNAL(aboutToFinish()),this,SLOT(continueMusic())); connect(this->singleWidget->ui->levelmode,SIGNAL(clicked()),this,SLOT(SingleToLogIn())); connect(this->logInwidget->returnUi()->pushButton_2,SIGNAL(clicked()),this,SLOT(LogInToSingle())); connect(this->logInwidget,SIGNAL(login_success(QString)),this,SLOT(LogInToTest(QString))); connect(this->testwidget->returnUi()->pushButton,SIGNAL(clicked()),this,SLOT(TestToLogIn())); // connect(this->singleWidget->ui->replay,SIGNAL(clicked()),this->replayerWidget,SLOT(GoInto())); //设置界面背景 QGraphicsScene *scene = new QGraphicsScene(this); scene->addItem(pad); scene->setBackgroundBrush(QBrush(QColor(0,0,0,255))); scene->setSceneRect(scene->itemsBoundingRect()); setScene(scene); showFullScreen(); //建立状态 stateMachine = new QStateMachine(this); MainState = new QState(stateMachine); TeamState = new QState(stateMachine); BeginState = new QState(stateMachine); TestState = new QState(stateMachine); ReplayerState = new QState(stateMachine); WebState = new QState(stateMachine); MapState = new QState(stateMachine); HumanaiState = new QState(stateMachine); ChatState = new QState(stateMachine); WidState = new QState(stateMachine); BeginMenuState= new QState(stateMachine); SingleState= new QState(stateMachine); OldMenuState = new QState(stateMachine); CheckMenuState = new QState(stateMachine); TeamMenuState = new QState(stateMachine); LogState = new QState(stateMachine); MainState->assignProperty(MainState, "z", 0); MainState->assignProperty(beginWindow->widget(), "windowOpacity", 1); stateMachine->setInitialState(MainState); stateMachine->start(); }
int main(int argc, char **argv) { QApplication app(argc, argv); QGraphicsScene scene; scene.setSceneRect(0, 0, 800, 480); QSizeF minSize(30, 100); QSizeF prefSize(210, 100); QSizeF maxSize(300, 100); QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A"); QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B"); QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C"); QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D"); QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E"); QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)"); QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)"); QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setSpacing(0); QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window); w->setPos(20, 20); w->setLayout(l); // vertical QGraphicsAnchor *anchor = l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); anchor = l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); anchor = l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); anchor = l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); anchor = l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); anchor = l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); anchor = l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); anchor = l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); anchor = l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop); anchor = l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom); anchor = l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop); anchor = l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom); // horizontal anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); anchor = l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); anchor = l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); anchor = l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); anchor = l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); anchor = l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); anchor = l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); anchor = l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); anchor = l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft); anchor = l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft); anchor = l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight); scene.addItem(w); scene.setBackgroundBrush(Qt::darkGreen); QGraphicsView *view = new QGraphicsView(&scene); view->show(); return app.exec(); }
//create all sub-widgets and display everything void PlayScreen::display(int screenWidth, int screenHeight, int gridSize) { this->screenWidth = screenWidth; this->screenHeight = screenHeight; grid = gridSize; numMoves = 0; seconds = 0; percentComplete = grid*grid; QFont font("Helvectica", 13); //set up scene and view QGraphicsScene *gScene = new QGraphicsScene(this); QGraphicsView *gView = new QGraphicsView(gScene); gView->setFixedSize(screenWidth, screenHeight); gScene->setBackgroundBrush(Qt::black); //set up all GridLayouts QGridLayout *layout = new QGridLayout(gView); playGrid = new QGridLayout(); QGridLayout *menuGrid = new QGridLayout(); layout->setContentsMargins(0,0,0,0); playGrid->setContentsMargins(0,0,0,0); menuGrid->setContentsMargins(0,0,0,0); gView->setLayout(layout); layout->addLayout(playGrid, 0, 0); layout->addLayout(menuGrid, 1, 0); //timer and move labels movesLabel = new QLabel("Moves: " + QString::number(numMoves)); timerLabel = new QLabel("Time: 0:0"); percentLabel = new QLabel("Percent: 0%"); menuGrid->addWidget(movesLabel,0,0); menuGrid->addWidget(timerLabel,1,0); menuGrid->addWidget(percentLabel,2,0); movesLabel->setFont(font); timerLabel->setFont(font); percentLabel->setFont(font); //menu buttons QPushButton *winButton = new QPushButton("DEBUG WIN"); QPushButton *pauseButton = new QPushButton("Pause/Play"); QPushButton *giveUpButton = new QPushButton("Give Up"); menuGrid->addWidget(winButton, 0, 1); menuGrid->addWidget(pauseButton, 1, 1); menuGrid->addWidget(giveUpButton, 2, 1); winButton->setFont(font); pauseButton->setFont(font); giveUpButton->setFont(font); connect(winButton, SIGNAL(clicked()), this, SLOT(winButtonClicked())); connect(pauseButton, SIGNAL(clicked()), this, SLOT(pauseButtonClicked())); connect(giveUpButton, SIGNAL(clicked()), this, SLOT(giveUpButtonClicked())); //import image QImageReader reader(imgPath); reader.setScaledSize(QSize(screenWidth, screenWidth)); QImage image = reader.read(); int eHeight = image.height(); int eWidth = image.width(); //cut image into tiles and position them for(int i = 0; i < grid; i++){ for(int j = 0; j < grid; j++){ if(!(i==grid-1 && j==grid-1)){ QPixmap pixmap = QPixmap::fromImage(image.copy(i*(eWidth/grid), j*(eHeight/grid), eWidth/grid, eHeight/grid)); QIcon icon(pixmap); Tile *button = new Tile(i, j, icon); button->setIconSize(QSize(eWidth/grid, eHeight/grid)); playGrid->addWidget(button, j, i); connect(button, SIGNAL(tileClicked(Tile*)), this, SLOT(handleTileClick(Tile*))); } } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; MyTimer timer; QPainterPath painter; QPainter paint; QBrush brush(Qt::red); QGraphicsScene scene; scene.addItem(r1); scene.addItem(r2); scene.addItem(r3); scene.addItem(r4); scene.addItem(r5); scene.addItem(r6); scene.addItem(r7); scene.addItem(r8); scene.addItem(r9); scene.addItem(r10); scene.addItem(r11); scene.addItem(r12); scene.addItem(r13); scene.addItem(r14); scene.addItem(r15); scene.addItem(r16); scene.addItem(r17); scene.addItem(r18); scene.addItem(r19); scene.addItem(r20); scene.addItem(r21); q1 = scene.addText("new text"); q1->setPos(-100,0); r1->setBrush(QColor(255, 255, 255, 127)); r2->setBrush(QColor(255, 255, 255, 127)); r3->setBrush(QColor(255, 255, 255, 127)); r4->setBrush(QColor(255, 255, 255, 127)); r5->setBrush(QColor(255, 255, 255, 127)); r6->setBrush(QColor(255, 255, 255, 127)); r7->setBrush(QColor(255, 255, 255, 127)); r8->setBrush(QColor(255, 255, 255, 127)); r9->setBrush(QColor(255, 255, 255, 127)); r10->setBrush(QColor(255, 255, 255, 127)); r11->setBrush(QColor(255, 255, 255, 127)); r12->setBrush(QColor(255, 255, 255, 127)); r13->setBrush(QColor(255, 255, 255, 127)); r14->setBrush(QColor(255, 255, 255, 127)); r15->setBrush(QColor(255, 255, 255, 127)); r16->setBrush(QColor(255, 255, 255, 127)); r17->setBrush(QColor(255, 255, 255, 127)); r18->setBrush(QColor(255, 255, 255, 127)); r19->setBrush(QColor(255, 255, 255, 127)); r20->setBrush(QColor(255, 255, 255, 127)); r21->setBrush(QColor(255, 255, 255, 127)); QPen pen(Qt::red); scene.addEllipse(-40,20,20,20,pen,brush); scene.addEllipse(300,80,20,20,pen,brush); scene.addEllipse(140,140,20,20,pen,brush); scene.setBackgroundBrush(QColor(160,200,190,140)); QGraphicsView view(&scene); view.show(); // window->setLayout(layout); //window->show(); // w.show(); return a.exec(); }
MainWindow::MainWindow() : QMainWindow() { // Create network view nView = new NetworkView(); QGraphicsScene *scene = new QGraphicsScene(); scene->setBackgroundBrush(QBrush(QColor(192, 192, 192))); nView->setScene(scene); setCentralWidget(nView); // Create tree view tView = new QTreeView(this); QDockWidget *treeDockWidget = new QDockWidget(tr("Tree"), this); treeDockWidget->setWidget(tView); addDockWidget(Qt::LeftDockWidgetArea, treeDockWidget); // Create controls view controls = new Controls(); controlWidget = new QDockWidget(tr("Controls"), this); controlWidget->setWidget(controls); addDockWidget(Qt::LeftDockWidgetArea, controlWidget); controlWidget->hide(); // Create properties view pView = new PropsView(this); propsWidget = new QDockWidget(tr("Properties"), this); propsWidget->setWidget(pView); addDockWidget(Qt::RightDockWidgetArea, propsWidget); propsWidget->hide(); // Create edit view eView = new EditView(this); editWidget = new QDockWidget(tr("Edit Properties"), this); editWidget->setWidget(eView); addDockWidget(Qt::RightDockWidgetArea, editWidget); editWidget->hide(); // Create menu fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open); fileMenu->addAction(tr("Save &As..."), this, SLOT(saveAsFile()), QKeySequence::Save/*As*/); fileMenu->addSeparator(); fileMenu->addAction(tr("Open in SUMO-GUI"), this, SLOT(openSUMO())); fileMenu->addAction(tr("Locate SUMO-GUI..."), this, SLOT(locateSUMO())); fileMenu->addSeparator(); fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit); viewMenu = menuBar()->addMenu(tr("&View")); viewMenu->addAction(treeDockWidget->toggleViewAction()); viewMenu->addAction(controlWidget->toggleViewAction()); viewMenu->addAction(propsWidget->toggleViewAction()); viewMenu->addAction(editWidget->toggleViewAction()); specialEditorsMenu = menuBar()->addMenu(tr("&Special Editors")); nmlJuncIcon = QPixmap(":/icons/nmlJunc1616.png"); tlLogicIcon = QPixmap(":/icons/tllogic1616.png"); specialEditorsMenu->addAction(nmlJuncIcon, tr("&Junction Editor"), this, SLOT(openJunctionEditor())); specialEditorsMenu->addAction(tlLogicIcon, tr("&tlLogic Editor"), this, SLOT(openTLEditor())); // Read settings from the nefs.ini file QSettings settings(QCoreApplication::applicationDirPath() + "/nefs.ini", QSettings::IniFormat); xmlPath = settings.value("paths/work").toString(); sumoguiPath = settings.value("paths/sumo").toString(); // Status bar statusBar()->showMessage(tr("Ready")); // Title and icon setWindowTitle(tr("Network Editor for SUMO")); setWindowIcon(QIcon(QPixmap(":/icons/NE4S128.png"))); modelLoaded = false; }