Example #1
0
void KPrView::startPresentationFromBeginning()
{
    KPrDocument * doc = dynamic_cast<KPrDocument *>( kopaDocument() );
    QList<KoPAPageBase*> slideshow = doc->slideShow();
    if ( !slideshow.isEmpty() ) {
        setActivePage( slideshow.first() );
    }
    startPresentation();
}
void KPrViewModePresentation::deactivate()
{
    emit deactivated();

    m_animationDirector->deactivate();
    KoPAPageBase * page = m_view->activePage();
    if ( m_endOfSlideShowPage ) {
        if ( page == m_endOfSlideShowPage ) {
            KPrDocument *document = static_cast<KPrDocument *>( m_view->kopaDocument() );
            page = document->slideShow().last();
        }
    }
    m_tool->deactivate();

    if (!m_baseCanvas) return;

    m_baseCanvas->setParent( m_savedParent, Qt::Widget );
    m_baseCanvas->setFocus();
    m_baseCanvas->setWindowState( m_baseCanvas->windowState() & ~Qt::WindowFullScreen ); // reset
    m_baseCanvas->show();
    KoCursor::setAutoHideCursor( m_baseCanvas, false );
    m_baseCanvas->setMouseTracking( true );
    m_view->setActivePage( page );

    // only delete after the new page has been set
    delete m_endOfSlideShowPage;
    m_endOfSlideShowPage = 0;

    delete m_animationDirector;
    m_animationDirector = 0;

    if ( m_presenterViewWidget ) {
        m_presenterViewWidget->setWindowState(
            m_presenterViewWidget->windowState() & ~Qt::WindowFullScreen );
        delete m_pvAnimationDirector;
        m_pvAnimationDirector = 0;

        delete m_presenterViewWidget;
        m_presenterViewWidget = 0;
        m_presenterViewCanvas = 0;
    }
    // make sure the page does not have an offset after finishing a presentation
    m_baseCanvas->setDocumentOffset(QPoint(0, 0));
}
void KPrViewModePresentation::activate( KoPAViewMode * previousViewMode )
{
    if (!m_baseCanvas) return;

    m_savedViewMode = previousViewMode;               // store the previous view mode
    m_savedParent = m_baseCanvas->parentWidget();
    m_baseCanvas->setParent( ( QWidget* )0, Qt::Window ); // set parent to 0 and

    QDesktopWidget desktop;

    KPrDocument *document = static_cast<KPrDocument *>( m_view->kopaDocument() );
    bool presenterViewEnabled = document->isPresenterViewEnabled();
    int presentationscreen = document->presentationMonitor();

    // add end off slideshow page
    m_endOfSlideShowPage = new KPrEndOfSlideShowPage( desktop.screenGeometry( presentationscreen ), document );
    QList<KoPAPageBase*> pages = document->slideShow();
    pages.append( m_endOfSlideShowPage );

    QRect presentationRect = desktop.screenGeometry( presentationscreen );

#ifdef Q_OS_LINUX
    // This breaks and is not required on Windows platforms
    m_baseCanvas->setParent(desktop.screen(presentationscreen), Qt::Window); // detach widget to the presentation screen
#endif

    m_baseCanvas->setWindowFlags( Qt::Window ); // make it a window

    // the main animation director needs to be created first since it will set the active page
    // of the presentation
    // the animation director needs to be set before m_baseCanvas->move is called as this might try to call
    // viewConverter.
    m_animationDirector = new KPrAnimationDirector( m_view, m_baseCanvas, pages, m_view->activePage() );
    // move and resize now as otherwise it is not set when we call activate on the tool.
    m_baseCanvas->setGeometry(presentationRect);
    m_baseCanvas->setWindowState( m_baseCanvas->windowState() | Qt::WindowFullScreen ); // make it show full screen

    // show and setFocus needs to be done after move and resize as otherwise the move and resize have no effect
    m_baseCanvas->show();
    m_baseCanvas->setFocus();

    KoCursor::setAutoHideCursor( m_baseCanvas, true );

    if ( presenterViewEnabled ) {

        if ( desktop.numScreens() > 1 ) {
            int newscreen = desktop.numScreens() - presentationscreen - 1; // What if we have > 2 screens?
            QRect pvRect = desktop.screenGeometry( newscreen );

            m_presenterViewCanvas = new KoPACanvas( m_view, document );
            m_presenterViewWidget = new KPrPresenterViewWidget( this, pages, m_presenterViewCanvas );
#ifdef Q_OS_LINUX
            // This breaks and is not required on Windows platforms
            m_presenterViewWidget->setParent( desktop.screen(newscreen), Qt::Window );
#endif
            m_presenterViewWidget->setGeometry(pvRect);
            m_presenterViewWidget->setWindowState(
                m_presenterViewWidget->windowState() | Qt::WindowFullScreen );
            m_presenterViewWidget->updateWidget( pvRect.size(), presentationRect.size() );
            m_presenterViewWidget->show();
            m_presenterViewWidget->setFocus();                             // it shown full screen

            m_pvAnimationDirector = new KPrAnimationDirector( m_view,
                    m_presenterViewCanvas, pages, m_view->activePage() );
        }
        else {
            kWarning() << "Presenter View is enabled but only found one monitor";
            document->setPresenterViewEnabled( false );
        }
    }

    m_tool->activate(KoToolBase::DefaultActivation, QSet<KoShape*>());

    emit activated();
    emit pageChanged( m_animationDirector->currentPage(), m_animationDirector->numStepsInPage() );
    emit stepChanged( m_animationDirector->currentStep() );
}