int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QApplication a(argc, argv); const QString fileAbsPath = a.arguments().at(1); qDebug("Opening %s...", qPrintable(fileAbsPath)); QMediaPlayer p; p.setMedia(QMediaContent(QUrl(fileAbsPath))); QGraphicsVideoItem* item = new QGraphicsVideoItem; QGraphicsScene* scene = new QGraphicsScene; scene->addText("TEST"); p.setVideoOutput(item); scene->addItem(item); scene->addRect(0, 0, 100, 100, QPen(Qt::red), QBrush(Qt::red)); item->setPos(0, 0); //QImage image(1920, 1080, QImage::Format_ARGB32); //image.fill(Qt::blue); //QPainter painter(&image); //painter.setRenderHint(QPainter::Antialiasing); //scene->render(&painter); QGraphicsView view(scene); //view.scene()->addItem(item); view.setViewport(new QOpenGLWidget); view.show(); p.play(); return a.exec(); }
void QGraphicsVideoItemPrivate::_q_present() { if (q_ptr->isObscured()) { q_ptr->update(boundingRect); surface->setReady(true); } else { q_ptr->update(boundingRect); } }
void QGraphicsVideoItemPrivate::updateRects() { q_ptr->prepareGeometryChange(); if (nativeSize.isEmpty()) { //this is necessary for item to receive the //first paint event and configure video surface. boundingRect = rect; } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { boundingRect = rect; sourceRect = QRectF(0, 0, 1, 1); } else if (aspectRatioMode == Qt::KeepAspectRatio) { QSizeF size = nativeSize; size.scale(rect.size(), Qt::KeepAspectRatio); boundingRect = QRectF(0, 0, size.width(), size.height()); boundingRect.moveCenter(rect.center()); sourceRect = QRectF(0, 0, 1, 1); } else if (aspectRatioMode == Qt::KeepAspectRatioByExpanding) { boundingRect = rect; QSizeF size = rect.size(); size.scale(nativeSize, Qt::KeepAspectRatio); sourceRect = QRectF( 0, 0, size.width() / nativeSize.width(), size.height() / nativeSize.height()); sourceRect.moveCenter(QPointF(0.5, 0.5)); } }
void QGraphicsVideoItemPrivate::_q_updateNativeSize() { QSize size = surface->surfaceFormat().sizeHint(); if (size.isEmpty()) size = rendererControl->property("nativeSize").toSize(); if (nativeSize != size) { nativeSize = size; updateRects(); emit q_ptr->nativeSizeChanged(nativeSize); } }
void QGraphicsVideoItemPrivate::updateRects() { q_ptr->prepareGeometryChange(); QSizeF videoSize; if (nativeSize.isEmpty()) { videoSize = rect.size(); } else if (aspectRatioMode == Qt::IgnoreAspectRatio) { videoSize = rect.size(); } else { // KeepAspectRatio or KeepAspectRatioByExpanding videoSize = nativeSize; videoSize.scale(rect.size(), aspectRatioMode); } displayRect = QRectF(QPointF(0, 0), videoSize); displayRect.moveCenter(rect.center()); boundingRect = displayRect.intersected(rect); }
MainWindow::MainWindow() { scene = new GraphicsScene(this); QGraphicsView *graphicsView = new QGraphicsView(scene); #if 0 QGraphicsVideoItem* videoItem = new QGraphicsVideoItem; videoItem->setSize(QSizeF(500, 480)); scene->addItem(videoItem); #endif //installEventFilter( scene ); textItem = new GraphicsTextItem(); QFont font; font.setPointSize(font.pointSize() * 2); font.setBold(true); textItem->setFont(font); textItem->setPlainText("Qt Everywhere!"); textItem->setDefaultTextColor(Qt::black); #if 0 QTextDocument* document = new QTextDocument; QTextCharFormat charFormat; charFormat.setFont(QFont("times", 24)); QPen outlinePen = QPen (QColor(255, 0, 0), 1, Qt::SolidLine); charFormat.setTextOutline(outlinePen); //字体轮廓 QTextCursor cursor = QTextCursor(document); cursor.insertText("Test", charFormat); textItem->setDocument(document); //textItem->setTextInteractionFlags(Qt::TextEditable); #endif textItem->setTextInteractionFlags(Qt::TextEditorInteraction); textItem->setZValue(1000.0); textItem->setPos(50, 300); scene->addItem(textItem); QWidget *tabAnimations = new QWidget; //tabAnimations->setMinimumHeight(200); //tabAnimations->setMaximumHeight(200); QHBoxLayout* hboxAnimations = new QHBoxLayout; hboxAnimations->addWidget(graphicsView); { QLabel *lbl = new QLabel(tr("Text duration:")); hboxAnimations->addWidget(lbl); } { QComboBox* m_durationTextCombo = new QComboBox(); //m_durationTextCombo->setEditable(true); for (int i = 2; i < 30; i = i + 2) m_durationTextCombo->addItem(QString().setNum(i)); hboxAnimations->addWidget(m_durationTextCombo); } { QToolButton *addPhotos = new QToolButton(); addPhotos->setText("Add photos"); hboxAnimations->addWidget(addPhotos); removeEventFilter(addPhotos); } { m_lineEdit = new LineEdit(this,scene); hboxAnimations->addWidget(m_lineEdit); //removeEventFilter(m_lineEdit); //m_lineEdit->installEventFilter( this ); } connect(m_lineEdit, SIGNAL(selectedTextSignal(const QString&)), scene, SLOT(activeVideoText(const QString&))); tabAnimations->setLayout(hboxAnimations); setCentralWidget(tabAnimations); setWindowTitle(tr("Character Map")); }