示例#1
0
void QtApplication::toggleFullscreen()
{
  QWidget *p = toplevelWidget();
  if(p->isFullScreen())
  { p->showNormal(); }
  else
  { p->showFullScreen(); }
}
示例#2
0
void Nexus::toggleFullscreen()
{
    QWidget* window = QApplication::activeWindow();

    if (window->isFullScreen())
        window->showNormal();
    else
        window->showFullScreen();
}
void VideoOutputEventFilter::switchFullScreen()
{
    if (!mpRenderer || !mpRenderer->widget())
        return;
    QWidget *window = mpRenderer->widget()->window();
    if (window->isFullScreen())
        window->showNormal();
    else
        window->showFullScreen();
}
示例#4
0
void VideoAreaWidget::leaveEvent(QMouseEvent *event) {
    QWidget::leaveEvent(event);

    QWidget* mainWindow = window();
    if (!mainWindow->isFullScreen()) return;

    bool visible = false;
    bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible));
    if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed";

    ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible));
    if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed";
}
bool VideoOutputEventFilter::eventFilter(QObject *watched, QEvent *event)
{
    // a widget shown means it's available and not deleted
    if (event->type() == QEvent::Show || event->type() == QEvent::ShowToParent) {
        mRendererIsQObj = !!mpRenderer->widget();
        return false;
    }
    if (!mRendererIsQObj)
        return false;
    /*
     * deleted renderer (after destroyed()) can not access it's member, so we must mark it as invalid.
     * hide event is sent when close. what about QEvent::Close?
     */
    if (event->type() == QEvent::Close || event->type() == QEvent::Hide) {
        mRendererIsQObj = false;
        return true;
    }
    if (!mpRenderer)
        return false;
    if (watched != mpRenderer->widget()
            /* && watched != mpRenderer->graphicsWidget()*/ //no showFullScreen() etc.
            )
        return false;
    switch (event->type()) {
    case QEvent::KeyPress: {
        QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
        int key = key_event->key();
        Qt::KeyboardModifiers modifiers = key_event->modifiers();
        switch (key) {
        case Qt::Key_F: { //TODO: move to gui
            //TODO: active window
            QWidget *w = mpRenderer->widget();
            if (!w)
                return false;
            if (w->isFullScreen())
                w->showNormal();
            else
                w->showFullScreen();
        }
            break;
        }
    }
        break;
    default:
        break;
    }
    return false;
}
示例#6
0
void MediaView::adjustWindowSize() {
    qDebug() << "Adjusting window size";
    Video *video = playlistModel->activeVideo();
    if (!video) return;
    QWidget *window = this->window();
    if (!window->isMaximized() && !window->isFullScreen()) {
        const double ratio = 16. / 9.;
        const double w = (double)videoAreaWidget->width();
        const double h = (double)videoAreaWidget->height();
        const double currentVideoRatio = w / h;
        if (currentVideoRatio != ratio) {
            qDebug() << "Adjust size";
            int newHeight = std::round((window->height() - h) + (w / ratio));
            window->resize(window->width(), newHeight);
        }
    }
}
示例#7
0
void VideoAreaWidget::mouseMoveEvent(QMouseEvent *event) {
    QWidget::mouseMoveEvent(event);

    QWidget* mainWindow = window();
    if (!mainWindow->isFullScreen()) return;

    // qDebug() << "VideoAreaWidget::mouseMoveEvent" << event->pos();

    const int x = event->pos().x();
    const int y = event->pos().y();

    bool visible = y <= 10;
    bool ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenToolbar", Qt::DirectConnection, Q_ARG(bool, visible));
    if (!ret) qDebug() << "showFullscreenToolbar invokeMethod failed";

    visible = x <= 10;
    ret = QMetaObject::invokeMethod(mainWindow, "showFullscreenPlaylist", Qt::DirectConnection, Q_ARG(bool, visible));
    if (!ret) qDebug() << "showFullscreenPlaylist invokeMethod failed";
}
void NcWidgetData::updateCursorShape( const QPoint& globalMousePos )
{
  if ( mWidget->isFullScreen() || mWidget->isMaximized() )
  {
    if ( mCursorShapeChanged )
      mWidget->unsetCursor();

    return;
  }

  mMoveMousePos.recalculate( globalMousePos, mWidget->frameGeometry() );

  if( mMoveMousePos.onTopLeftEdge || mMoveMousePos.onBottomRightEdge )
  {
    mWidget->setCursor( Qt::SizeFDiagCursor );
    mCursorShapeChanged = true;
  }
  else if( mMoveMousePos.onTopRightEdge || mMoveMousePos.onBottomLeftEdge )
  {
    mWidget->setCursor( Qt::SizeBDiagCursor );
    mCursorShapeChanged = true;
  }
  else if( mMoveMousePos.onLeftEdge || mMoveMousePos.onRightEdge )
  {
    mWidget->setCursor( Qt::SizeHorCursor );
    mCursorShapeChanged = true;
  }
  else if( mMoveMousePos.onTopEdge || mMoveMousePos.onBottomEdge )
  {
    mWidget->setCursor( Qt::SizeVerCursor );
    mCursorShapeChanged = true;
  }
  else
  {
    if ( mCursorShapeChanged )
    {
      mWidget->unsetCursor();
      mCursorShapeChanged = false;
    }
  }
}
void QApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e)
{
    // This operation only makes sense after the QApplication constructor runs
    if (QCoreApplication::startingUp())
        return;

    QApplication::desktop()->d_func()->updateScreenList();

    // signal anything listening for screen geometry changes
    QDesktopWidget *desktop = QApplication::desktop();
    emit desktop->resized(e->index);

    // make sure maximized and fullscreen windows are updated
    QWidgetList list = QApplication::topLevelWidgets();
    for (int i = list.size() - 1; i >= 0; --i) {
        QWidget *w = list.at(i);
        if (w->isFullScreen())
            w->d_func()->setFullScreenSize_helper();
        else if (w->isMaximized())
            w->d_func()->setMaxWindowState_helper();
    }
}
示例#10
0
bool EventFilter::eventFilter(QObject *watched, QEvent *event)
{
    Q_UNUSED(watched);
    AVPlayer *player = static_cast<AVPlayer*>(parent());
    if (!player || !player->renderer() || !player->renderer()->widget())
        return false;
    if (qobject_cast<QWidget*>(watched) != player->renderer()->widget()) {
        return false;
    }
#ifndef QT_NO_DYNAMIC_CAST //dynamic_cast is defined as a macro to force a compile error
    if (player->renderer() != dynamic_cast<VideoRenderer*>(watched)) {
       // return false;
    }
#endif
    QEvent::Type type = event->type();
    switch (type) {
    case QEvent::KeyPress: {
        QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
        int key = key_event->key();
        Qt::KeyboardModifiers modifiers = key_event->modifiers();
        switch (key) {
        case Qt::Key_C: //capture
            player->captureVideo();
            break;
        case Qt::Key_N: //check playing?
            player->playNextFrame();
            break;
        case Qt::Key_P:
            player->play();
            break;
        case Qt::Key_Q:
        case Qt::Key_Escape:
            qApp->quit();
            break;
        case Qt::Key_S:
            player->stop(); //check playing?
            break;
        case Qt::Key_Space: //check playing?
            qDebug("isPaused = %d", player->isPaused());
            player->pause(!player->isPaused());
            break;
        case Qt::Key_F: { //TODO: move to gui
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            if (w->isFullScreen())
                w->showNormal();
            else
                w->showFullScreen();
        }
            break;
        case Qt::Key_Up: {
            AudioOutput *ao = player->audio();
            if (modifiers == Qt::ControlModifier) {
                qreal s = player->speed();
                if (s < 1.4)
                    s += 0.02;
                else
                    s += 0.05;
                if (qAbs<qreal>(s-1.0) <= 0.01)
                    s = 1.0;
                player->setSpeed(s);
                return true;
            }
            if (ao && ao->isAvailable()) {
                qreal v = player->audio()->volume();
                if (v > 0.5)
                    v += 0.1;
                else if (v > 0.1)
                    v += 0.05;
                else
                    v += 0.025;
                player->audio()->setVolume(v);
                qDebug("vol = %.3f", player->audio()->volume());
            }
        }
            break;
        case Qt::Key_Down: {
            AudioOutput *ao = player->audio();
            if (modifiers == Qt::ControlModifier) {
                qreal s = player->speed();
                if (s < 1.4)
                    s -= 0.02;
                else
                    s -= 0.05;
                if (qAbs<qreal>(s-1.0) <= 0.01)
                    s = 1.0;
                s = qMax<qreal>(s, 0.0);
                player->setSpeed(s);
                return true;
            }
            if (ao && ao->isAvailable()) {
                qreal v = player->audio()->volume();
                if (v > 0.5)
                    v -= 0.1;
                else if (v > 0.1)
                    v -= 0.05;
                else
                    v -= 0.025;
                player->audio()->setVolume(v);
                qDebug("vol = %.3f", player->audio()->volume());
            }
        }
            break;
        case Qt::Key_O: {
            if (modifiers == Qt::ControlModifier) {
                //TODO: emit a signal so we can use custome dialogs?
                openLocalFile();
            } else/* if (m == Qt::NoModifier) */{
                emit showNextOSD();
            }
        }
            break;
        case Qt::Key_Left:
            qDebug("<-");
            player->seekBackward();
            break;
        case Qt::Key_Right:
            qDebug("->");
            player->seekForward();
            break;
        case Qt::Key_M:
            if (player->audio()) {
                player->audio()->setMute(!player->audio()->isMute());
            }
            break;
        case Qt::Key_R: {
            VideoRenderer* renderer = player->renderer();
            VideoRenderer::OutAspectRatioMode r = renderer->outAspectRatioMode();
            renderer->setOutAspectRatioMode(VideoRenderer::OutAspectRatioMode(((int)r+1)%2));
        }
            break;
        case Qt::Key_T: {
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            Qt::WindowFlags wf = w->windowFlags();
            if (wf & Qt::WindowStaysOnTopHint) {
                qDebug("Window not stays on top");
                w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint);
            } else {
                qDebug("Window stays on top");
                w->setWindowFlags(wf | Qt::WindowStaysOnTopHint);
            }
            //call setParent() when changing the flags, causing the widget to be hidden
            w->show();
        }
            break;
        case Qt::Key_F1:
            help();
            break;
        default:
            return false;
        }
        break;
    }
    case QEvent::DragEnter:
    case QEvent::DragMove: {
        QDropEvent *e = static_cast<QDropEvent*>(event);
        e->acceptProposedAction();
    }
        break;
    case QEvent::Drop: {
        QDropEvent *e = static_cast<QDropEvent*>(event);
        QString path = e->mimeData()->urls().first().toLocalFile();
        player->stop();
        player->load(path);
        player->play();
        e->acceptProposedAction();
    }
        break;
    case QEvent::GraphicsSceneContextMenu: {
        QGraphicsSceneContextMenuEvent *e = static_cast<QGraphicsSceneContextMenuEvent*>(event);
        showMenu(e->screenPos());
    }
        break;
    case QEvent::ContextMenu: {
        QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event);
        showMenu(e->globalPos());
    }
        break;
    default:
        return false;
    }
    return true; //false: for text input
}
示例#11
0
void MainView::keyPressEvent(QKeyEvent *event)
{
	if ( (event->modifiers() & Qt::ControlModifier || event->modifiers() & Qt::ShiftModifier)
			&& event->key() == Qt::Key_Print)
	{
		event->accept();

		QPrinter printer;
		printer.setOutputFormat(QPrinter::PdfFormat);
		printer.setFullPage(true);
		printer.setResolution(300);

		QSvgGenerator svggen;
		svggen.setResolution(90);



		if (event->modifiers() & Qt::ShiftModifier)
		{
			// Print scene
			printer.setOutputFileName("screenshot-scene.pdf");
			printer.setPaperSize(scene()->sceneRect().size().toSize(), QPrinter::Point);
			QPainter painter(&printer);
			painter.setRenderHint(QPainter::Antialiasing);
			scene()->render( &painter );

			svggen.setFileName("screenshot-scene.svg");
			svggen.setSize(scene()->sceneRect().size().toSize());
			QPainter svgPainter(&svggen);
			svgPainter.setRenderHint(QPainter::Antialiasing);
			scene()->render(&svgPainter);

			QImage image(2 * scene()->sceneRect().size().toSize(), QImage::Format_ARGB32);
			image.fill(Qt::transparent);
			QPainter pmapPainter(&image);
			pmapPainter.setRenderHint(QPainter::Antialiasing);
			//pmapPainter.scale(2,2);
			scene()->render(&pmapPainter);
			image.save("screenshot-scene.png");
		}
		else
		{
			// Print view
			printer.setOutputFileName("screenshot-view.pdf");
			printer.setPaperSize(viewport()->rect().size(), QPrinter::Point);
			QPainter painter(&printer);
			painter.setRenderHint(QPainter::Antialiasing);
			render(&painter);

			svggen.setFileName("screenshot-view.svg");
			svggen.setSize(viewport()->rect().size());
			QPainter svgPainter(&svggen);
			svgPainter.setRenderHint(QPainter::Antialiasing);
			render(&svgPainter);

			QImage image(2 * viewport()->rect().size(), QImage::Format_ARGB32);
			image.fill(Qt::transparent);
			QPainter pmapPainter(&image);
			pmapPainter.setRenderHint(QPainter::Antialiasing);
			render(&pmapPainter);
			image.save("screenshot-view.png");
		}
	}
	else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_F11)
	{
		event->accept();
		QWidget* window = this;
		while (window->parentWidget()) window = window->parentWidget();

		if (window->isFullScreen()) window->showNormal();
		else window->showFullScreen();
	}
	else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_F10)
	{
		event->accept();
		if (miniMap->width() == MINIMAP_DEFAULT_WIDTH && miniMap->height() ==  MINIMAP_DEFAULT_HEIGHT)
			setMiniMapSize(width(), height());
		else setMiniMapSize(MINIMAP_DEFAULT_WIDTH, MINIMAP_DEFAULT_HEIGHT);
	}
	else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_F9)
	{
		event->accept();
		if (miniMap->isVisible()) miniMap->hide();
		else miniMap->show();
	}
	else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_F7)
	{
		event->accept();
		showTimers_ = ~showTimers_;
		updateInfoLabels();
	}
	else View::keyPressEvent(event);
}
示例#12
0
bool EventFilter::eventFilter(QObject *watched, QEvent *event)
{
    //qDebug("EventFilter::eventFilter to %p", watched);
    Q_UNUSED(watched);
    /*if (watched == reinterpret_cast<QObject*>(player->renderer)) {
        qDebug("Event target is renderer: %s", watched->objectName().toAscii().constData());
    }*/
    //TODO: if not send to QWidget based class, return false; instanceOf()?
    QEvent::Type type = event->type();
    switch (type) {
    case QEvent::MouseButtonPress:
        qDebug("EventFilter: Mouse press");
        static_cast<QMouseEvent*>(event)->button();
        //TODO: wheel to control volume etc.
        return false;
        break;
    case QEvent::KeyPress: {
        //qDebug("Event target = %p %p", watched, player->renderer);
        //avoid receive an event multiple times
        int key = static_cast<QKeyEvent*>(event)->key();
        switch (key) {
        case Qt::Key_C: //capture
            player->captureVideo();
            break;
        case Qt::Key_N: //check playing?
            player->playNextFrame();
            break;
        case Qt::Key_P:
            player->play();
            break;
        case Qt::Key_S:
            player->stop(); //check playing?
            break;
        case Qt::Key_Space: //check playing?
            qDebug("isPaused = %d", player->isPaused());
            player->pause(!player->isPaused());
            break;
        case Qt::Key_F: { //TODO: move to gui
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            if (w->isFullScreen())
                w->showNormal();
            else
                w->showFullScreen();
        }
            break;
        case Qt::Key_Up:
            if (player->audio) {
                qreal v = player->audio->volume();
                if (v > 0.5)
                    v += 0.1;
                else if (v > 0.1)
                    v += 0.05;
                else
                    v += 0.025;
                player->audio->setVolume(v);
                qDebug("vol = %.3f", player->audio->volume());
            }
            break;
        case Qt::Key_Down:
            if (player->audio) {
                qreal v = player->audio->volume();
                if (v > 0.5)
                    v -= 0.1;
                else if (v > 0.1)
                    v -= 0.05;
                else
                    v -= 0.025;
                player->audio->setVolume(v);
                qDebug("vol = %.3f", player->audio->volume());
            }
            break;
        case Qt::Key_O: {
            //TODO: emit a signal so we can use custome dialogs
            QString file = QFileDialog::getOpenFileName(0, tr("Open a video"));
            if (!file.isEmpty())
                player->play(file);
        }
            break;
        case Qt::Key_Left:
            qDebug("<-");
            player->seekBackward();
            break;
        case Qt::Key_Right:
            qDebug("->");
            player->seekForward();
            break;
        case Qt::Key_M:
            if (player->audio) {
                player->audio->setMute(!player->audio->isMute());
            }
            break;
        case Qt::Key_T: {
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            Qt::WindowFlags wf = w->windowFlags();
            if (wf & Qt::WindowStaysOnTopHint) {
                qDebug("Window not stays on top");
                w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint);
            } else {
                qDebug("Window stays on top");
                w->setWindowFlags(wf | Qt::WindowStaysOnTopHint);
            }
            //call setParent() when changing the flags, causing the widget to be hidden
            w->show();
        }
            break;
        default:
            return false;
        }
        break;
    }
    default:
        return false;
    }
    return true; //false: for text input
}
示例#13
0
void QGLContext::updatePaintDevice()
{
    Q_D(QGLContext);
    d->update = false;
#if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
        if(d->paintDevice->devType() == QInternal::Widget) {
            QWidget *w = (QWidget *)d->paintDevice;
            aglSetHIViewRef((AGLContext)d->cx, (HIViewRef)w->winId());
        } else if(d->paintDevice->devType() == QInternal::Pixmap) {
            QPixmap *pm = (QPixmap *)d->paintDevice;
            aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(),
                            qt_mac_pixmap_get_bytes_per_line(pm), qt_mac_pixmap_get_base(pm));
        } else {
            qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
        }
    } else
#endif
    {
#ifndef Q_OS_MAC64
        if(d->paintDevice->devType() == QInternal::Widget) {
            //get control information
            QWidget *w = (QWidget *)d->paintDevice;
            HIViewRef hiview = (HIViewRef)w->winId();
            WindowPtr window = qt_mac_window_for(hiview);
#ifdef DEBUG_OPENGL_REGION_UPDATE
            static int serial_no_gl = 0;
            qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w,
                   w->metaObject()->className(), w->objectName().toLatin1().constData(),
                   hiview, window, w->handle() ? "Inside" : "Outside");
#endif

            //update drawable
            if(0 && w->isWindow() && w->isFullScreen()) {
                aglSetDrawable((AGLContext)d->cx, 0);
                aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w));
                w->hide();
            } else {
                AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window);
                if(old_draw != new_draw)
                    aglSetDrawable((AGLContext)d->cx, new_draw);
            }

            if(!w->isWindow()) {
                QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area

#ifdef DEBUG_OPENGL_REGION_UPDATE
                if(clp.isEmpty()) {
                    qDebug("  Empty area!");
                } else {
                    QVector<QRect> rs = clp.rects();
                    for(int i = 0; i < rs.count(); i++)
                        qDebug("  %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height());
                }
#endif
                //update the clip
                if(!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT))
                    aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT);
                if(clp.isEmpty()) {
                    GLint offs[4] = { 0, 0, 0, 0 };
                    aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
                    if(aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
                        aglDisable((AGLContext)d->cx, AGL_CLIP_REGION);
                } else {
                    HIPoint origin = { 0., 0. };
                    HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0);
                    const GLint offs[4] = { qRound(origin.x),
                                            w->window()->frameGeometry().height()
                                                    - (qRound(origin.y) + w->height()),
                                            w->width(), w->height() };
                    aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs);
                    aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)clp.handle(true));
                    if(!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION))
                        aglEnable((AGLContext)d->cx, AGL_CLIP_REGION);
                }
            }
        } else if(d->paintDevice->devType() == QInternal::Pixmap) {
            QPixmap *pm = (QPixmap *)d->paintDevice;
            PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle());
            aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(),
                            GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm));
        } else {
            qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!");
        }
#endif // Q_OS_MAC64
    }
    aglUpdateContext((AGLContext)d->cx);
}